Wednesday, September 14, 2011

Reading and modifying OS X plist files on the command line

OS X uses plist files to store configuration information - you can think of them as OS X's version of the windows registry.

To read a plist you can use:
defaults read /Library/Preferences/com.apple.CrashReporter
and similarly to write a value to a plist
sudo defaults write /Library/Preferences/com.apple.CrashReporter SomeKey -bool TRUE
sudo defaults write /Library/Preferences/com.apple.CrashReporter SomeKey -string "somevalue"
and delete
sudo defaults delete /Library/Preferences/com.apple.CrashReporter SomeKey
You can also use plutil to dump an XML version to stdout:
plutil -convert xml1 -o - filename.plist
as well as convert between binary and XML formats. Xcode also ships with a plist editor (standalone prior to XCode 4, built-in since then).

And if that wasn't enough there's also PlistBuddy, here's an example command to print a particular key 'BluetoothVersionNumber':
/usr/local/bin/PlistBuddy -c Print:BluetoothVersionNumber /Library/Preferences/com.apple.Bluetooth.plist

2 comments:

Anonymous said...

"Xcode also ships with a plist editor."

Well, it did for Xcode < 4.3. There is no longer such a beast, which is why i started a search that landed me on your blog. Thank you, as i was otherwise coming up empty.

Anonymous said...

Thanks, first result on google for a reason!