Friday, July 20, 2012

plistbuddy and defaults on OS X

I use defaults to read most plists on OS X, but it has an annoying habit of being very chatty in the logs. If you want to write code to query for a value that may or may not be present, it ends up being very noisy. e.g. even if you suppress stderr like this:
defaults read /Library/Preferences/com.apple.CrashReporter.plist DOESNT_EXIST 2> /dev/null
For some reason the defaults tool thinks the failure to read the value is really important and writes a log line like:
defaults[34157]: The domain/default pair of (com.apple.CrashReporter.plist, DOESNT_EXIST) does not exist
So if you don't want the spurious logs, you can use plist buddy to do the same thing:
/usr/local/bin/PlistBuddy -c Print:DOESNT_EXIST /Library/Preferences/com.apple.CrashReporter.plist

No comments: