1

I am making a script that puts on a defaults write thing to true. How can I check before it's it's true or false?

1

1 Answer 1

1

You can use defaults read. For example, if I wanted to check for AppleShowAllFiles, I would do:

~$ defaults read com.apple.Finder AppleShowAllFiles
YES

Which would return YES in the stdout. You can make your script execute this command and read it from stdout.

Another perhaps unrealistic (and quite dangerous) option would be to read directly from ~/Library/Preferences/com.apple.<ID>.plist, however most of then are rather unreadable. For example, com.apple.Finder.plist around the area of AppleShowAllFiles looks like this:

NSNavOutlineColumnSettings.v1_FXMyDocumentsArrangeGroupViewBy_AppleShowAllFiles_ViewSettingsDictionary_CopyProgressWindowLocation_FK_StandardViewSettings_8NSTableView Hidden Columns

This is not recommended though

2
  • 1
    I would say - always stick with defaults read. That layer is there to protect you from underlying storage changes. If Apple moves the place where they store a specific key or cache it in a database file, you will miss that if you are parsing a file from the filesystem.
    – bmike
    Commented Dec 22, 2015 at 14:40
  • It somewhat funny you picked AppleShowAllFiles for your example because by default it does not exist and the output is The domain/default pair of (com.apple.Finder, AppleShowAllFiles) does not exist when it doesn't. :) Commented Dec 22, 2015 at 14:43

You must log in to answer this question.

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