MacOS – How to check what mode is already on on defaults write

defaultsmacos

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?

Best Answer

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