how can i parse the output of the OS X defaults read
terminal command?
it appears to output the 'old' NeXTSTEP plist format; things that look like:
{
"Apple Global Domain" = {
AppleAntiAliasingThreshold = 4;
AppleCollationOrder = root;
i tried writing the output to a file and converting with plutil
, but it chokes:
> defaults read > defaults.txt
> plutil -convert xml1 defaults.txt
2014-02-02 21:29:14.856 plutil[56896:707] CFPropertyListCreateFromXMLData(): Old-style
plist parser: missing semicolon in dictionary on line 10835. Parsing will be abandoned.
Break on _CFPropertyListMissingSemicolon to debug.
defaults.txt: Property List error: Unexpected character { at line 1 / JSON error: No
value for key in object around character 28.
why, you ask?
i'd like to store the defaults values in git so i can keep a record as a change setting and diff after applying changes, but it seems the serialization in defaults read
is not 'line order stable': dictionaries do not dump their keys in consistent order, causing a huge amount of noise. if i can parse defaults read
, i can then pipe the data out through an order-consistent serializer.