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.
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.
defaults Set preferences, the macOS user defaults system works with both the OS and with individual applications.
Set preferences, the macOS user defaults system works with both the OS and with individual applications.
On macOS dscl is a very useful to access data in the local user directory or another directory the Mac is bound to. For example you can read a user’s UID with: This output looks easy enough to parse, you can just use cut or awk: However, dscl is a treacherous. Its output format changes, depending on the contents of an attribute.
How To Change Preferences from the Command Line on macOS? The user friendly way to change an application preferences (aka settings) in macOS is to use the UI menu as Application Name > Preferences... or by typing the shortcut ⌘ +, from the given application.
You’re a lucky guy, just few days ago someone released a parser of the NeXTSTEP plist format on PyPi – nsplist.
plutil can convert to xml or json
#!/bin/bash
f='~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure'
x="$(plutil -convert xml1 -o - "$f")"
j="$(plutil -convert json -o - "$f")"
-o -
means: print result to stdout$f
is the input file in plist format
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With