Add a SharePoint bookmark in Microsoft Office 2011 to 100 Macs using Bash

Making changes on one Mac can easily be made using the GUI interface, but managing a large number of workstations (especially when performing the same operation) can unnecessarily consume too much of your time.

I recently had to add a bookmark for a SharePoint location for Microsoft Office 2011 applications. Doing so on one Mac was very easy by using the GUI interface but deploying the same change to 100 Macs would not have been possible without taking a few days and a few extra white hairs.

Thanks to Darren Wallace, I managed to complete the task with just a couple of terminal lines. I used the PlistBuddy terminal utility to edit the com.microsoft.office.plist file in my Library/Preferences folder.

Great job, I thought to myself. But how do I edit this file on every Mac and in every users’ home folder?

Luckily, the customer had a Casper solution in place that meant I just had to write a script in Bash and let Casper deal with the hard work.

Then I remembered that David Acland, my Technical Director, had written a previous blog about writing data into existing home folders as part of an installation package. I jumped on the web, found the blog, and that was it. I had a piece of art, which could serve as a base for my script.

Recycling scripts is an essential skill in the scripting world. What makes things even easier is that David’s script had invaluably helpful comments under each line. I easily found what I didn’t need and deleted those sections, which essentially made the script universal.

In the loop, I inserted my PlistBuddy commands, and that was it. Job done. In a couple of hours, I had a script that will add SharePoint locations for every user on every Mac in a medium sized organisation.

Here is what the script looks like:

#!/bin/sh

counter=`ls /Users | grep "[A-z 0-9]" | grep -c -v -E 'Shared|Guest|.localized|.DS_Store'`
     # Outputs the number of folders in the /Users directory, excluding the Shared & Guest directories

 killall cfprefsd
 	# Restarts the process to allow plist changes to be applied

     while [ $counter -ne 0 ]
     # Loop start
          do
               targetFolder=`ls /Users | grep "[A-z 0-9]" | grep -v -E 'Shared|Guest|.localized|.DS_Store' | head -$counter | tail -1`
                    # Gets the target folder name. We prefer an ls loop as otherwise you will need to work around non-mobile AD accounts
                    #and using ls on the /Users folder (or wherever the home folders are on the target Macs) ensures that you only get
                    #real device “users” and not all of the system accounts.

                /usr/libexec/PlistBuddy -c "Add :favoriteslist:Children:0 dict" /Users/$targetFolder/Library/Preferences/com.microsoft.office.plist
                	#Adds new dictionary under favouritelist, under Children

                /usr/libexec/PlistBuddy -c "Add :favoriteslist:Children:0:Name string "$4"" /Users/$targetFolder/Library/Preferences/com.microsoft.office.plist
                	#Adds the string Name in the newly created dictionary with a variable in its value $4 that can be replaced by a constant value.
			#The $4 will allow Casper to use custom labels preset in a policy.

                /usr/libexec/PlistBuddy -c "Add :favoriteslist:Children:0:URL string "$5"" /Users/$targetFolder/Library/Preferences/com.microsoft.office.plist
                	#Adds the URL string in the newly created dictionary with a variable in its value $5 that can be replaced by a constant value.
			#The $5 will allow Casper to use custom labels preset in a policy.

               counter=$(( $counter - 1 ))
                    # Reduces the counter by 1
     	done

killall cfprefsd
	# Restarts the process to allow plist changes to be applied

exit 0


Disclaimer:

While the author has taken care to provide our readers with accurate information, please use your discretion before acting upon information based on the blog post. Amsys will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.

4 Replies to "Add a SharePoint bookmark in Microsoft Office 2011 to 100 Macs using Bash"

  • Neil Martin

    I’d just like to ask, purely out of interest and for my own self-learning, since you’re using Casper. Did you consider managing this via configuration profiles or MCX before scripting it? If you did, and decided against it, I’d love to know the reasons why.

    Cheers!

    Neil.

  • Ivaylo Mihaylov

    That’s a good point Graham. For that reason we would scope it to logged users and other Casper triggers like startup and login.

  • Ivaylo Mihaylov

    Hey Neil,

    I didn’t think of using MCX when I needed the solution but I can’t see why wouldn’t it work and it would have probably been easier. It would be interesting to try that.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *