Automatically Customize Mac OS X with a Bash Script: 27 Defaults Write Commands, custom .aliases, .bash_profile, etc

Sep 9, 2011 - 8 Comments

Bash script to customize many aspects of Mac OS X

If you’re an advanced user and setting up a new Mac, you probably customize the OS with a ton of defaults write commands and .alias adjustments. These are things you can either enter manually, use an easy tool like LionTweaks, or check out this new great script from GitHub called .osx.

Note: this is obviously geared towards more advanced users who are comfortable with the command line and understand what changes they are making. Read the full article to see if these adjustments are right for you. If any of this seems confusing, you probably shouldn’t be making these changes or at least using this method, and the aforementioned LionTweaks utility may be a better fit. Proceed at your own risk.

Option 1) The Full Suite: customize .bash_profile, .bash_prompt, .aliases, git, and Mac OS X with defaults writes

If you want to make a ton of settings adjustments to .bash_profile, .aliases, .gitconfig, and all of the below defaults write commands, you can use this git command in the Terminal to do everything. Before jumping into this one, it’d be a good idea to review the files yourself to make sure the changes are things you want.

git clone https://github.com/mathiasbynens/dotfiles.git && cd dotfiles && ./bootstrap.sh

The .aliases file is pretty useful, but includes some commands like ngrep that are not preinstalled by default, so you’ll need homebrew or otherwise to install those.

Option 2) The defaults write changes to Mac OS X only

If you’re not interested in all of the terminal adjustments and aliases, you can just also just get the .osx file from this link

In either case, after git is finished or you have grabbed the .osx file yourself, you can execute the script with:

./.osx

This will activate all of the commands listed below at once. We’ve covered just about all of these before but having them in a centralized location and easily writable from a bash script is very useful when you’re setting up a new Mac.

Option 3: Selectively customizing OS X by entering the defaults write commands yourself

Here’s the full list of defaults write commands that are contained within the .osx file, review this before launching the script or just pick and choose which ones you want to use by putting them into the Terminal:

# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3

# Enable the 2D Dock
defaults write com.apple.dock no-glass -bool true

# Disable menu bar transparency
defaults write -g AppleEnableMenuBarTransparency -bool false

# Expand save panel by default
defaults write -g NSNavPanelExpandedStateForSaveMode -bool true

# Expand print panel by default
defaults write -g PMPrintingExpandedStateForPrint -bool true

# Disable shadow in screenshots
defaults write com.apple.screencapture disable-shadow -bool true

# Enable highlight hover effect for the grid view of a stack (Dock)
defaults write com.apple.dock mouse-over-hilte-stack -bool true

# Enable spring loading for all Dock items
defaults write enable-spring-load-actions-on-all-items -bool true

# Disable press-and-hold for keys in favor of key repeat
defaults write -g ApplePressAndHoldEnabled -bool false

# Disable auto-correct
defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false

# Disable window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

# Disable disk image verification
defaults write com.apple.frameworks.diskimages skip-verify -bool true
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true

# Automatically open a new Finder window when a volume is mounted
defaults write com.apple.frameworks.diskimages auto-open-ro-root -bool true
defaults write com.apple.frameworks.diskimages auto-open-rw-root -bool true

# Avoid creating .DS_Store files on network volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

# Disable Safari’s thumbnail cache for History and Top Sites
defaults write com.apple.Safari DebugSnapshotsUpdatePolicy -int 2

# Enable Safari’s debug menu
defaults write com.apple.Safari IncludeDebugMenu -bool true

# Remove useless icons from Safari’s bookmarks bar
defaults write com.apple.Safari ProxiesInBookmarksBar “()”

# Disable send and reply animations in Mail.app
defaults write com.apple.Mail DisableReplyAnimations -bool true
defaults write com.apple.Mail DisableSendAnimations -bool true

# Disable Resume system-wide
defaults write NSGlobalDomain NSQuitAlwaysKeepsWindows -bool false

# Enable Dashboard dev mode (allows keeping widgets on the desktop)
defaults write com.apple.dashboard devmode -bool true

# Reset Launchpad
rm ~/Library/Application\ Support/Dock/*.db

# Show the ~/Library folder
chflags nohidden ~/Library

# Disable local Time Machine backups
sudo tmutil disablelocal

# Kill affected applications
for app in Safari Finder Dock Mail; do killall “$app”; done

# Fix for the ancient UTF-8 bug in QuickLook (http://mths.be/bbo)
echo “0×08000100:0″ > ~/.CFUserTextEncoding

If you’re making manual changes, many of these will require either the Finder, Dock, or other applications to be relaunched before they are activated. This is generally handled through the script with the second to last command (“Kill affected applications”) but with so many changes being made, it may be easier to just reboot your Mac to insure everything is working properly.

Thanks to Brian for sending this in!

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: William Pearson in Command Line, Mac OS X, Tips & Tricks

8 Comments

» Comments RSS Feed

  1. m3 t00 says:

    I definitely don’t want all the . files but here’s what I did with the defaults:

    git clone https://raw.github.com/mathiasbynens/dotfiles/master/.osx

    Go through and # comment out what you don’t want and then:

    ./.osx

  2. Buck Rogers says:

    if you want to undo these afterwards do a find and replace all for ‘true’ to ‘false’

  3. Ed says:

    I wish I understood how to use git better. Can anyone point me to a primer?

    When I try m3t00′s method above, I get a fatal error, and “did you run git update-server-info on the server?”

    I would if I knew what it meant!!

  4. Oliver says:

    I think ‘m3 t00′ meant to write:

    wget https://github.com/mathiasbynens/dotfiles/blob/master/.osx

    as the url in that git command points to the raw file (as if you had cloned the repo and just checked out that one file.)

    To actually clone the repository, one would need to run:

    git clone git://github.com/mathiasbynens/dotfiles.git

  5. Cliff Rowley says:

    That git undo push alias is an accident waiting to happen. Though I’m sure the OP has a good reason for including dangerous commands in a script any old newbie can download and install without thinking.

  6. [...] Automatically Customize Mac OS X with a Bash Script: 27 Defaults Write Commands, custom .aliases, .b… (tags: macosx bash leopard shell via:zite) [...]

  7. [...] Automatically Customize Mac OS X with a Bash Script: 27 Defaults Write Commands, custom .aliases, .b… – [...]

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates