If you're a long time Windows power user and are recently switching over to the Mac, you may have wondered if there was something analogous to the Windows Registry .
However, if you've always been more of a Mac user, don't run away just yet as you may learn something.
In case you don't know what the Windows Registry is, here is a short definition from our good ol' friend Wikipedia.
Windows Registry is a hierarchical database that stores configuration settings and options on Microsoft Windows operating systems. It contains settings for low-level operating system components and for applications running on the platform that have opted to use the Registry.
You have probably already figured that since it's called the Windows Registry
that there is likely not a Mac Registry
that looks/operates the same way.
You are correct; however, where do all of the system and applications settings get stored if there is no registry?
If the Windows Registry is a place where system and application settings are stored, then the Mac equivalent of the Windows Registry would be a series of .plist
files in several preferences folder on the Mac.
While researching how to automate bootstrapping my Mac development computer, I stumbled upon large number of .plist
files in several folders that correlate to the installed applications and system settings. And BOOM just like that I discovered the holy grail of my Mac's system and application settings - kind of like the first time lift up the curtain and discover the Windows Registry.
What are .plist
files?
A .plist
file is a configuration file that contains a list of properties in either plain text or binary format. I'll go into more later about how to read and update values in these files later in the post.
For more info on plist files, check out the Wikipedia page...
Where can I find plist files?
I know of at least 2 locations that host the common system and application .plist
files.
The first one is user specific and is in the following location:
~/Library/Preferences/
In my case (since my user name is jason
)
/Users/jason/Library/Preferences/
The second location one is at the root of the system:
/Library/Preferences/
If you look into these folders you'll see a large number of plist files that follow reverse domain name convention (like com.apple.sample
).
Here are some (not all) examples of system configuration plist files:
com.apple.ActivityMonitor.plist
com.apple.AddressBook.plist
com.apple.finder.plist
com.apple.preference.general.plist
com.apple.TextEdit.plist
com.apple.Safari.plist
In the same folder as the sample configuration files listed above are where you can find plist
files that are associated to applications installed on the system.
com.apple.dt.Xcode.plist
com.google.Chrome.plist
org.herf.Flux.plist
com.skype.skype.plist
Now that we can find system and application configuration plist
files, if you try to open them in a text editor you may notice that many of them are in a binary format which would be challenging to read and understand, let alone edit.
How do I read these files?
The Mac comes with a command line utility called defaults for reading and writing to these .plist
files.
If you take an example from the above list of plist files, you can, at the command prompt type the following:
defaults read com.apple.fin<tab>
(where <tab>
is the tab key that allows tab completion of the rest of the property list format) and be sure to exclude the .plist
of the end so:
defaults read com.apple.finder
will print out all of the properties to the console so you can inspect what's there.
You can pipe this output to grep and filter for a setting name when doing searches. Once you've found a property name you want to look at you can pass it into the defaults read
command to get the value of that specific property.
Example reading a single property:
defaults read com.apple.finder AppleShowAllExtensions
How to change property list settings?
WARNING
Just like modifying the Windows Registry can mess up your system, you need to take care modifying system or application plist
settings.
WARNING
Most of these settings can be changed by navigating to the application or system's respective preferences U.I. and just changing settings manually. However, the whole reason I ran down this path was to learn how to automate these setting changes.
When I first tried to change the settings I tried manually modifying the plist files with a GUI tool built into the Xcode developer tools.
However, and I have yet to understand the internals of this, after I made the changes to the plist file they would automatically get overwritten after a few seconds. So it seems that there is some official source of these values somewhere that for some reason overwrite the ones in these folder. I probably have that all wrong - but was an observation I had.
So if my understanding above is somewhat correct, how did I update the source?
Similar to reading property list values you can use the defaults command line tool to write
changes back to the .plist
files.
As an example, here's how I update Finder to show file extensions.
defaults write com.apple.finder AppleShowAllExtensions -boolean true
The configuration options are now endless.
In summary:
Using my new knowledge that app and system settings can be found in both /Library/Preferences
and ~/Library/Preferences
and I can use the command line tool defaults to read/write to understand and update settings.
I can now create a simple .sh
script that allows me to pre-configure a new development machine with all of the settings I would like.
Now, each time I catch myself trying to use an application's preferences U.I. I stop myself and try to find that setting in a plist file and create a CLI command that I can save into my development setup script.
Happy Mac Settings Hacking!