How to properly manipulate defaults in OS X

TerminalIconXThe “defaults” system in OS X is Apple’s preferences-writing and management system, which many programs and system services use to read and write preferences to disk.

In general, the preferences written to disk are those that the developer intends to be modifiable by you or to be otherwise configured; however, in addition to these there are quite often a number of hidden settings that are in a particular program’s defaults. Unfortunately there is no direct way to extract an entire list of supported defaults; however, at times some are discovered, and subsequently tried by many.

Background

In general, to adjust a program’s defaults manually, you can either modify the preferences file directly, or preferably use the “defaults” command in the OS X Terminal, in the following manner:

defaults ACTION DOMAIN KEY VALUE

In this scheme, the ACTION is usually either “read” or “write,” DOMAIN is the program’s domain (e.g., “com.apple.TextEdit” for TextEdit), KEY is the defaults setting name, and VALUE is the new value for the domain, optionally preceded by a type of value.

For example, the following is a custom setting for showing hidden files in the OS X Finder (with “write” as the ACTION, “com.apple.Finder” as the DOMAIN, “appleshowallfiles” as the KEY, and “true” as the VALUE):

defaults write com.apple.Finder appleshowallfiles true

Note that the value here is “true,” but can also be “yes” or “-bool 1,” to indicate a true value. In cases where the value is an integer, you can just type the integer or specify it by “-int NUMBER.” For a string value (text) you can specify this with “-string TEXT.”

How to manipulate defaults

While many Web sites offer the simple “defaults write” command to make a hidden adjustment, they often do not include how to undo this. The routine for which only takes one additional step:

  1. Defaults checking in the Terminal

    Running the “defaults read” routine will let you know if the setting does not exist, or does with a default value (click for larger view).

    Check if the defaults setting already exists.
    Running “defaults write” will add a defaults key and value pair to a program’s preferences file; however, this key and value may not have previously existed. Therefore, first be sure of the status of the setting you are adjusting, by performing a read for it. To do this, in the Terminal run “defaults read DOMAIN KEY” to check whether or not it exists. This may look like the following example:

    defaults read com.apple.Finder appleshowallfiles
    

    In this example, the key “appleshowallfiles” does not exist by default, so the Terminal will output this message. If it does exist by default, then the Terminal would output its value instead of this message.
  2. Apply the new defaults setting
    With the current status of the setting known, you can now apply the “defaults write” command to change the setting, and then log out and log back in, or perform whatever other action is needed to make the custom setting active.

The key here is that you know how to properly undo the changes you made by using the “defaults write” routine. If the setting you are adjusting initially did not exist, then you can delete it by using the following command:

defaults delete DOMAIN KEY
 (e.g., "defaults delete com.apple.Finder appleshowallfiles")

If on the other hand the setting’s value was just changed, you can use the “defaults write” command again, but this time use the old value you determined in step 1 above.

5 thoughts on “How to properly manipulate defaults in OS X

  1. xAirbusdriver

    What I need is something like:

    defaults print my.brain.memory changed-defaults-list true

    1. Topher Kessler Post author

      You can list the current set of defaults in a program’s preference files simply using the following command (e.g., for TextEdit):

      defaults read com.apple.TextEdit

      Note that this will not give you the list of all possible defaults, but only those that are currently set either by the program, or by you through the use of the “defaults” command.

      1. xAirbusdriver

        It’s not the changes in the preferences files I need. It’s a list of apps in which I’ve made the changes. That’s stored in my.brain.memory but I’ve fried the I/O and can’t access that data! 😉 I think I might be able to rewire a Thunderbolt to SCSI cable…

        Seriously, I now make an effort to record these kinds of changes in a growing text file.

        So, why are you working on Saturday!! Being your own boss is usually more work than being an employee! 😐 And who do you call if you’re sick?! 😎

  2. Pingback: Disable new power button sleep mode in OS X Mavericks | MacIssues

Comments are closed.