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
?
MacOS – How to check what mode is already on on defaults write
defaultsmacos
Related Question
- How to change shape defaults in keynote
- How to use the defaults command with App Groups
- MacOS – How to check what permissions an app store app will be granted
- How to handle (e.g. correctly escape) parens in a ‘defaults write …’ key value
- MacOS – Can “defaults write” command line configure the menu bar on macOS
Best Answer
You can use defaults read. For example, if I wanted to check for
AppleShowAllFiles
, I would do: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 ofAppleShowAllFiles
looks like this:This is not recommended though