Thursday, April 4, 2013

Track of Defaults Write Commands Used in Mac OS X Automatically

7:49 AM


Note: If this tutorial worked for you (and it should work), please leave a comment below. Thanks.

If you like to tweak Mac OS X with a lot of defaults write commands from the terminal, you already know how hard it can be to keep track of them. Sure you can query command history for specific command syntax, and you can always use grep to find executed defaults commands, but there’s a better way to keep track of them all, and that’s by keeping an automatically updated text file that stores a list of all used defaults tweaks. This makes it very easy to keep track of which defaults commands have been activated or disabled on a specific Mac.

The other advantage to this trick is that it keeps the list completely separated from general command history, meaning if command history is cleared the defaults list will continue to be around for future reference.

Use a command line text editor that you are comfortable with, we’ll stick with nano since it is simple and fairly user friendly:
nano .bash_profile
Paste in the following string on a new line within .bash_profile
PROMPT_COMMAND='echo "$(history 1 | grep "defaults")" | sed '/^$/d' >> ~/Documents/defaults.txt'
Note the standard location for the defaults list file is the user home directory ~/Documents/ folder in a file called “defaults.txt”, feel free to change that if desired.

Save the document by hitting Control+O then exit out of nano by hitting Control+X

The document called ‘defaults.txt’ will be generated the first time the string ‘defaults’ has been detected in command execution. Each new defaults entry will be added to a numerical list added on it’s own line. This is perhaps best enabled fresh after a restore or right away on a new Mac, that way the defaults.txt file will contain the full list of all defaults commands ever used on the given Mac.

If you use cat to view the file, you may see something like this:
501 cat ~/Documents/defaults.txt
502 defaults read com.apple.Finder
503 defaults write com.apple.dock springboard-rows -int 4
504 defaults write com.apple.dock springboard-columns -int 4;killall Dock
505 defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences RememberedNetworks
506 defaults write com.apple.systemsound "com.apple.sound.uiaudio.enabled" -int 1
507 defaults read com.apple.systemsound
508 defaults write com.apple.systemsound "com.apple.sound.uiaudio.enabled" -int 0
509 tail -f ~/Documents/defaults.txt
As mentioned, it will grab anything with ‘defaults’ in the command syntax, which includes using cat, tail, nano, and anything else on the defaults.txt file itself. Additionally, it will keep track of not only the changes made with defaults write, but also anytime a defaults command has been read with defaults read, or removed with defaults delete commands.

Limit to “defaults write” Only
If you’d rather exclusively see ‘defaults write’ strings, use the following in .bash_profile instead:
PROMPT_COMMAND='echo "$(history 1 | grep "defaults write")" | sed '/^$/d' >> ~/Documents/defaults-write.txt'
Whichever you use, the resulting file is a generic text document, and it can also be opened in nano, vi, TextEdit, TextWrangler, BBedit, emacs, or whichever the preferred client is. This makes it easy to not only keep track of for systems administration purposes, but also for sharing lists with friends and colleagues.

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

0 comments:

Post a Comment

 

© 2013 iFlasha. All rights resevered. Designed by Templateism

Back To Top