X

Check defaults before altering hidden settings in OS X

When making custom changes to a program that go beyond its preferences settings, it can be a good idea to make sure you have a way to revert your edits.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
4 min read

OS X applications and services often contain a number of hidden settings that can be used to tweak your Mac's behavior to improve performance or provide an option that is not available by default. To manage these hidden options, you can use the "defaults" terminal command to edit the target preferences file associated with a service and manually adjust a variable's value.

Since the defaults command performs these edits in a single line in the Terminal, it is relatively easy to use and is often suggested as a way to edit property list (plist) files, which are the default format for preferences in OS X.

The property list format is simply an XML-based arrangement of variables (called "keys") and their associated values. Programs often are coded to have a number of variables that can be set to non-default values. Often these are for debugging purposes when the program is in development, but some control the settings that users access through the program's preferences window.

All of the variables a program uses are hard-coded with default values, and when the program first loads it creates its preferences file to contain at least the subset of these that are user-editable. It may also store a few of its hidden variables.

You can change these variables by editing the plist files for the program, and you can also add a hidden variable to a service's preferences file, changing its value. The defaults command follows this pattern:

defaults action target variable value

For example, the Finder will by default hide a number of system files to prevent clutter on your computer, but you can set the Finder to show all files by overriding the default value of the hidden AppleShowAllFiles variable:

defaults write com.apple.Finder AppleShowAllFiles true

This command tells the defaults tool to write a change to the Finder's preference file for the current user (denoted by the use of the "com.apple.Finder" domain). It then specifies the variable to use, and also the variable's value. In this case the value is simply a Boolean yes or no (true/false) so it can be reversed to disable the feature if necessary. Other variables that people may change when tweaking their systems may have more complex values, including text strings or graded values, such as those that govern the speed of user interface animations like the Dock's genie effect.

Before you write a hidden setting to a preferences file, it's a good idea to check to see if the variable is present in that file already, and if so what its default value is. The reason is that if you want to undo the change later, the procedure is slightly different depending on whether the variable was already present in the file or if you added it.

To find out, run the "defaults" command in a way that attempts to read the value of the specified variable. In the example above involving the Finder, before changing the AppleShowAllFiles variable you would run the following command:

defaults read com.apple.Finder AppleShowAllFiles

Since the AppleShowAllFiles variable should not exist in the Finder's preferences file, you should see an output in the Terminal similar to the following:

2012-10-09 21:03:18.439 defaults[5869:707]
The domain/default pair of (com.apple.Finder, AppleShowAllFiles) does not exist

If the variable had existed in that file, then the Terminal output would have listed it and its current value. The "does not exist" response means the variable is not in the file by default. If you use the "defaults write" command to set the value of AppleShowAllFiles, that variable will be added to the preferences file.

If the variable you changed wasn't in the preferences file originally, you can revert it to its original value by simply using the "defaults delete" command to remove the variable. You don't need to provide the variable's value. The command follows this pattern:

defaults delete target variable

So, continuing the example above, suppose you no longer want the Finder to show all files. To remove the AppleShowAllFiles variable and revert the preferences file to its original state you would run the following command:

defaults delete com.apple.Finder AppleShowAllFiles

In cases where the "defaults read" command shows that the variable does exist in the file already, however, take note of its listed value before changing it. If you want to revert your changes, you'll need to overwrite the variable instead of simply deleting it. In other words, to undo your changes, use the "defaults write" command again, but this time use the original value for the variable.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.