DEV Community

santisbon
santisbon

Posted on • Updated on

Finding the right macOS `defaults` command

Automating the setup of a clean macOS install is a lot easier when you know which keys to edit via the defaults command. Since there's no official listing of all the keys, there are places online that give you the most commonly used ones and try to stay up to date with the names of the keys in the latest release of macOS, with varying degrees of success. The best way is to grab the correct names directly from your Mac.

Note: First, make sure your terminal has Full Disk Access in System Settings > Privacy and Security.

The format to edit your macOS preferences is
defaults write $DOMAIN $KEY -$TYPE $VALUE

And you can list all the domains with
defaults domains | tr ', ' '\n'

You can figure out the correct domain and key names by comparing the output of defaults read before and after manually changing a setting in the UI. You can also specify a domain to narrow down the output but it's not required so don't worry if you're not sure which domain is affected by the setting you're interested in. Remember to kill any affected apps to apply the changes.

Example:

defaults read com.apple.finder > before.txt
# Change Finder Settings in the UI
# to clear "Show warning before changing an extension" 
defaults read com.apple.finder > after.txt
diff before.txt after.txt
# <     FXEnableExtensionChangeWarning = 1;
# ---
# >     FXEnableExtensionChangeWarning = 0;
Enter fullscreen mode Exit fullscreen mode

Now check the type and you got a command you can add to any automation you wish.

defaults read-type com.apple.finder FXEnableExtensionChangeWarning
# Type is boolean
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false
killall Finder 2> /dev/null
Enter fullscreen mode Exit fullscreen mode

If you can't find a key where you expected it, remove the domain from your query or check the global domain. This one affects Finder but it's in the global domain instead of com.apple.finder. Other ways to specify the global domain are -g, -globalDomain, and NSGlobalDomain.

defaults read "Apple Global Domain" AppleShowAllExtensions
# 1
defaults read-type "Apple Global Domain" AppleShowAllExtensions
# Type is boolean
Enter fullscreen mode Exit fullscreen mode

Other commands to try:

defaults help
defaults find $WORD
defaults read com.apple.dock | grep wvous # Hot Corners
Enter fullscreen mode Exit fullscreen mode

Want an example of a setup script? Check out mine.

Top comments (2)

Collapse
 
ngeorger profile image
Nicolás A. Georger

Useful as f... thank you very much

Collapse
 
caparkaya profile image
Yağız Çaparkaya

This helped me on finding my way managing Mac OS settings, thank you. :)