1

I can read preferences from a domain, and I can read a single key deep, for example:

defaults read com.apple.Terminal "Window Settings"

However, I cannot dereference a key deeper than depth=1 with the defaults command. For example, I want to read the Basic under Window Settings. I would expect to be able to do something like this:

defaults read com.apple.Terminal "Window Settings" Basic

It looks like defaults only works with a fixed depth:

The domain/default pair of (com.apple.Terminal, Basic) does not exist

But surely I can use it to manipulate dictionaries? What utilities are available?

1

1 Answer 1

0

defaults doesn't do what you want. For that, you can use plutil - Property List Util. Read the man page fully to grok what it can do. I'll provide a starting point:

To check out nested keys in Terminal's plist, you can say something like this:

plutil -extract "Window Settings.Basic.CursorColor" xml1 -o - ~/Library/Preferences/com.apple.Terminal.plist

You may notice there's an option to output json, which seems nice. But plists are allowed to use binary data (base64 encoded, ofc). And somehow json output doesn't play well with that.

Anyway. plutil wants to work with whole files so you can't edit a single key. You can do this manually with Xcode which provides a nice graphical user interface to edit plists. Or you can use PlistBuddy. Here's a tutorial. https://fgimian.github.io/blog/2015/06/27/a-simple-plistbuddy-tutorial/

2
  • The xml1 format may be more useful than json. It's also what apple internally prefers to use (like in .mobileconfig)
    – hym3242
    Commented May 30 at 4:27
  • And, if anyone would like a 1-liner to change a key: /usr/libexec/PlistBuddy -c 'Set :"Window Settings":Basic:warnOnShellCloseAction 0' ~/Library/Preferences/com.apple.Terminal.plist
    – Phil Cohen
    Commented Aug 7 at 23:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .