NSGlobalDomain, NSRegistrationDomain, and the Preference Inheritance Chain

NSGlobalDomain and NSRegistrationDomain are special domains in the preference system. You can think of them as default preferences and default default preferences (respectively) in the preference inheritance chain.

NSGlobalDomain

The NSGlobalDomain contains preferences that are used by every application that is launched, not just by a certain application. These preferences are mostly set through the various preference panels in the System Preferences application.

NSRegistrationDomain

The NSRegistrationDomain is where all the default preferences are stored. This domain does not exist on your hard drive anywhere; instead it is constructed in memory when an application launches.

These values are read-only and cannot be changed.

The Preference Inheritance Chain

What is the preference inheritance chain? It’s the steps an application goes through to find a requested preference value. When an application is asked for a specific preference, it will look in a specific order among various domains to return that preference.

First, an application will look in the NSArgumentDomain. Usually, this domain is empty — the only way to fill values in this domain is to start the application from the command line and give it arguments. Those arguments are placed into the NSArgumentDomain. (This is a good way to temporarily override a preference value if you need to, or are wanting to test something out before actually changing the value.)

Next, it will look into its own preference file. Most of the time it will find the requested preference here and stop searching.

If the preference is not found in the application’s preference file, it will next look in the NSGlobalDomain file for it.

Finally, if it's not found in any of the above, the application will look in the NSRegistrationDomain to see if the preference can be found there.

Knowing the way preferences are searched for, you can actually use this to override a global preference on a per application basis. As an example, let’s say you have an application that you wish to be displayed in a different language than your default one. Normally, you would have to go to System Preferences, change what the default language is, then launch (or relaunch if it’s running) the application. After you’re done, you will need to remember to go back into System Preferences and reset your default language. But, knowing now that you can override that setting for just that application, you can copy over the AppleLanguages preference from the NSGlobalDomain into the application’s preferences and change the ordering of the languages used there. Now, you no longer need to go to System Preferences to change the language and the application will always launch using the language you want it to.