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.
Graham Gilbert
Note that this is only guaranteed to work for users that aren’t logged in. Plistbuddy isn’t cfprefsd aware, so you’re going to have issues if the apps are running. To not have to fight with cfprefsd, you’re going to have to start looking at something like python (http://macmule.com/2014/02/07/mavericks-preference-caching/)
Graham Gilbert
Note that this is only guaranteed to work for users that aren’t logged in. Plistbuddy isn’t cfprefsd aware, so you’re going to have issues if the apps are running. To not have to fight with cfprefsd, you’re going to have to start looking at something like python (http://macmule.com/2014/02/07/mavericks-preference-caching/)
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.
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
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
Chapligatramp
У нее исчезли боли в спине, стало намного легче ходить и передвигаться.Чтобы сделать МТБ своими руками, потребуется тщательно продумать его месторасположение.Кроме креплений, в комплекте имеются блочки, трос из металла и грузы, составляющие стек на 105 кг.Чтобы поддерживаться при выполнении упражнений в положении стоя перед тренажером, можно воспользоваться горизонтальной ручкой.грузовой стек 80 кг 15400 грн.
Тренажеры мтб для тренировок по системе бубновского купить у известного завода-производителя реабилитационных тренажеров для центров кинезитерапии бубновского . Производитель тренажеров и аксессуаров для лечения межпозвоночной грыжи Спортхеппи доставку осуществляет к Вам домой по всей Украине : Днепр , Киев , Кропивницкий , Одесса , Сумы , Харьков , Черновцы курьерской компанией Интайм или транспортом завода без предоплаты в течении 1-4 дней после заказа. Стоимость доставки 475 грн.
Vincent Brock
I’m commenting to make you be aware of of the impressive encounter my girl went through browsing your blog. She noticed lots of details, most notably how it is like to possess an amazing coaching character to make other individuals easily completely grasp a variety of multifaceted subject matter. You undoubtedly surpassed visitors’ expected results. Thank you for distributing these valuable, dependable, explanatory and fun thoughts on your topic to Mary.
Leonora Varnes
I have been looking something about that forever.
ForexUnfago
Auto forex. https://se.forex-stock-bitcoin-brokers.com
scriptless testing tools
660243 241221Maximize your by how a large amount of gear are employed internationally and will often impart numerous memory using that your is also fighting that is a result from our team rrnside the twenty very first centuries. every day deal livingsocial discount baltimore washington 695579
Chaturbate Engel
887836 554649some genuinely choice content material on this internet web site , saved to my bookmarks . 662767
https://flowad.net/home.php?mod=space&uid=248721
I think everything posted was actually very reasonable.
But, consider this, what if you composed a catchier title?
I am not saying your information is not good.,
but suppose you added a title to maybe get people’s attention? I mean Firefox CCK2 lockdown Casper Extension Attributes is a
little boring. You might look at Yahoo’s front page and note how they create news titles to get people to click.
You might try adding a video or a picture or two to grab readers interested about everything’ve written. In my opinion,
it could bring your posts a little livelier.
สล็อตวอเลท
893926 593567Im glad I identified your article. I would never have created sense of this topic on my own. Ive read a couple of other articles on this topic, but I was confused until I read yours. 573818
fake the best audemars piguet fake
876157 519961Some genuinely nice stuff on this site , I enjoy it. 647153