Adjusting OS X preferences with plistbuddy
On an OS X system a lot of applications keep their preferences in so called .plist-files. These files can be of 3 different types:
Apple binary property list
XML document text
JSON
The binary type is the most common, but in essence are they all the same. I did not encounter the JSON format on my own system, but that does not really matter. What matters is that these files contain valuable information and can be edited with the right tool. Most common way to edit these files is via the preferences menu option of the application. Though some of the preferences might not even be accessible via the preferences menu. Let's first use the non-risky way of taking a look in the plist files with the plutil tool.
Let's take a look at what we can do with plutil and the screensaver preferences file: ~/Library/Preferences/com.apple.screensaver.plist. In the terminal we'll take a look at what information this plist file holds. We use the -p option of plutil:
$ plutil -p com.apple.screensaver.plist { "askForPassword" => 1 "askForPasswordDelay" => 0 }
It stores the information wether or not to ask for a password and the delay (in minutes) before the screensaver ask for a password. With PlistBuddy you can edit the plist file from the command line. PlistBuddy is very likely to reside on your system already, as it is used by a lot of applications during updates. On my system I found 8 PlistBuddy installs under /Library/Receipts. Let's use /Library/Receipts/iTunesX.pkg/Contents/Resources/PlistBuddy, as that one seems the most recent of the 8 (from 12 March 2010, shasum 1a4c57624b100bf8b22a9381c433b858654c3911). First query the file again:
$ /Library/Receipts/iTunesX.pkg/Contents/Resources/PlistBuddy -c "Print" com.apple.screensaver.plist Dict { askForPasswordDelay = 0.000000 askForPassword = 1 }
As seen, the result is the same as before. But with PlistBuddy we can edit the file too:
/Library/Receipts/iTunesX.pkg/Contents/Resources/PlistBuddy -c "Set askForPassword 0" com.apple.screensaver.plist
So if you combine this with your crontab you can set that you want your screensaver to be password protected during daytime and in the evening not.
0 20 * * 1-5 /Library/Receipts/iTunesX.pkg/Contents/Resources/PlistBuddy -c "Set askForPassword 0" com.apple.screensaver.plist 0 7 * * 1-5 /Library/Receipts/iTunesX.pkg/Contents/Resources/PlistBuddy -c "Set askForPassword 1" com.apple.screensaver.plist
In a later post I'll show a more useful example.













