Keep track of hidden settings changes made using the defaults command


The defaults command is a great way to change hidden settings in Mac OS X. These hidden settings are generally options that developers decided to hide in the final version of their app for some reason — they might be too complicated for the average user, or maybe they cluttered up the preferences window too much. But while these settings no longer appear in the application preferences, we can still change them through the Terminal by using defaults. As long as you know the right command, it’s simply a case of typing it in and pressing Return. For some examples just check out our previous tips.

One problem with this is keeping track of all the changes you have made. A recent article over on MacOSXHints proposed a solution, but it’s a bit inelegant as it involves creating a replacement defaults script that intercepts your commands first. Here’s a much more straightforward solution that I came up with. It basically involves first logging previously made changes to a file, then setting up a script that appends any future changes to the file as they are made.

This simple solution involves using the history command. To see what this does, start by opening up Terminal (located in Applications/Utilities), typing history and pressing Return. Up to the last 500 things you have typed into the Terminal should appear in a numbered list. We don’t care about most of them, so we can filter this list using grep as follows:

history | grep "defaults write"

As before, just enter this line and press Return. A list of all the defaults commands you have ever made should appear. Unfortunately, as history only stores the 500 most recent items, over time the older defaults commands will start to disappear. So on its own this isn’t really sufficient to keep an accurate log, but we can use it to help us make our own permanent log. To do this, start by entering the following command into the Terminal, adjusting the file path if you want to.

history | grep "defaults write" >> ~/Documents/defaultsLog.txt

Open bash_profile in TextEdit

Now we have all our previous changes saved, we can set up a script that adds any future ones onto the end of that same file. Open up TextEdit and choose Open from the File menu (Command-O). Go to your user folder and then press Command-Shift-. (Period) to show hidden files. The one we are looking for is .bash_profile. Don’t worry if you can’t find it — instead you can just create a new file and save it in your user folder as .bash_profile. Either way, once you have this file open, add the following line to the end:

PROMPT_COMMAND='echo "$(history 1 | grep "defaults write")" | sed '/^$/d' >> ~/Documents/defaultsLog.txt'

This is a quick little script that runs every time a new command prompt is shown. It simply checks if the last command contained defaults write, and if so, adds it onto the end of the file.

blog comments powered by Disqus