Enable Key Repeat in Lion

If it’s been killing you like it’s been killing me and you want to enable key repeat in Lion just type the following in the command line:

defaults write -g ApplePressAndHoldEnabled -bool false

I couldn’t put up with it any longer.

I also added this user default to my list in a previous post: Mac OS X User Defaults. It contains a pretty thorough list of suggested and commonly sought changes.

Mount NTFS Drives on Mac

Looking to connect an NTFS drive on your Mac? That’s just what NTFSMounter is for. It’s a simple menubar app that allows you to access NTFS volumes.

When the application is running it simply checks for NTFS volumes. If a drive has been automatically mounted by the system, you will have to eject the volume first. NTFS Mounter won’t eject the volume by itself to avoid any other applications to crash if they are accessing files on the volume. Once you have ejected the volume, you can try to select it again from the menu.

I’ve read reports online that NTFSMounter doesn’t work on Lion (I last tried it on Snow Leopard), but there are a number of different proposed fixes. Here’s one via Terminal:

# Look up where the identifier for your NTFS disk first
# Alternatively you can look it up in "Apple Menu (alt/option) >> System Information >> USB"
diskutil list

# First umount the automounted volume
diskutil umount /dev/disk2s2

# Make a new directory
mkdir /backup

# Mount your drive
/sbin/mount_ntfs -o rw /dev/disk2/s2 /backup

Another Terminal alternative I found:

# Look up where the identifier for your NTFS disk first
# Alternatively you can look it up in "Apple Menu (alt/option) >> System Information >> USB"
diskutil list

# Make a directory to you mount your drive
sudo mkdir /Volumes/usb1

# Mount the volume in the new location
sudo mount -t ntfs /dev/disk1s1 /Volumes/usb1/

According to the mount man page, you should be able to add the -w option for read-write capability.

Another source suggested downloading the ntfs-3g files and substituting sudo mount -t ntfs /dev/disk1s1 /Volumes/usb1/ with sudo mount -t ntfs-3g /dev/disk1s1 /Volumes/usb1/.

I read about a Google code project called MacFUSE too. This might be worth a shot as well.

Lastly, these two options (Buy or Try) have had some success: Tuxera NTFS and Paragon NTFS.

If you aren’t worried about backing up files for a specific filesystem on your external drive, you can always partition it with exFat, the new “Fat64”. (In case you didn’t know, Fat32 doesn’t support files over 4GB.)

Leverage Git Config & Autocomplete Git Commands

Git Logo

I’ve already discussed customizing your shell and command prompt. To me, it is equally important to leverage Git configuration and autocomplete Git commands. You should also check out how to show the current Git branch in your Bash prompt.

Git Config

There are a lot of cool things you can do to customize Git just the way you like it. Most of these ideas are personalized versions of the git config customizations found at the Git website.

To create succinct, efficient commands in Git, create aliases for both the shell and for Git. Add the following code snippet to your .profile or .bash_profile:

alias gst='git status'
alias gco='git checkout'
alias gci='git commit'
alias grb='git rebase'
alias gbr='git branch'
alias gpl='git pull'
alias gpu='git push'
alias gad='git add -A'
alias gmt='git mergetool'
alias bdf='git diff'
alias glg='git log --date-order --all --graph --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glg2='git log --date-order --all --graph --name-status --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'

Next add the following code to your ~/.gitconfig file:

[alias]
st = status
co = checkout
ci = commit
rb = rebase
br = branch
pl = pull
pu = push
ad = add
mt = mergetool
df = diff
lg = log --graph --name-status --oneline

Now reload your shell and you’re good to go. I’d also recommend you configure the following settings:

  • Color UI. Adds color to commands like git status so you can read the output more easily. It’s as simple as git config --global color.ui true.
  • Code Editor. I like to use vim, but Sublime would be a great alternative. git config --global core.editor vim.
  • Diff & Merge Tool. I downloaded the DiffMerge app for my MacBook Pro and the P4Merge for my Windows box. These tools allow me to compare code or resolve code conflicts when I run into them. This is worth the time it takes to set up before hand. Read how at Customizing Git – Git Configuration: External Merge and Diff Tools.

Below is what my .gitconfig file looks like now (Updated 2012-09-28):

[user]
        name = John Doe
        email = johndoe@doe.com
[alias]
        st = status
        co = checkout
        ci = commit
        rb = rebase
        br = branch
        pl = pull
        pu = push
        ad = add
        mt = mergetool
        lg = log --graph --name-status --oneline
[core]
        editor = vim
        #autocrlf = true
[color]
        ui = true
[merge]
        tool = kdiff3
        ff = true
[mergetool "kdiff3"]
        path = /usr/local/bin/kdiff3
        #path = C:/Program Files (x86)/KDiff3/kdiff3.exe

        guitool = kdiff3
[difftool]
        path = /usr/local/bin/kdiff3
        #path = C:/Program Files (x86)/KDiff3/kdiff3.exe

Autocomplete Git Commands

To add autocomplete for your Git commands, download the git-completion.bash file. The easiest way I know to do it is by using the following curl command in the shell:

curl https://github.com/git/git/raw/master/contrib/completion/git-completion.bash -OL

The -O options tells curl to output a local file with the same name as the remote file. Thus, the name of the file is extracted from the given URL.

The -L option allows curl to redirect if the appropriate location is indicated with a Location: header and a 3XX response code. curl will redo the request using the new location.

Once you get the the git-completion.bash file, find a place to store it permanently. I put mine with the rest of my shell scripts in ~/bin. Then add the following code snippet to your .profile or .bash_profile file:

source ~/git-completion.bash

Customize Your Shell & Command Prompt

As mentioned in a previous post, we received some new MacBooks and a Mac Mini at work. Since most of my team prefers using PCs, I was able to get my hands on one. I immediately noticed how different it was from the one I use at home, so I started customizing it right away. I found I had forgotten how to do a couple things and it took me longer than I would have liked to search the web, so I’ve decided to dedicate a short post on how to customize your shell and command prompt in Mac OS X.

If you use Linux or Windows (think cygwin or git bash) this may apply to you too. If you don’t use any sort of shell, well, then you might just want this for future reference.

Apps

Terminal is the default app that comes with Mac OS X. Another great app is iTerm 2 (Free). It adds a lot of functionality that some users find lacking in Terminal.

General Preferences

Some programs that run the shell allow you to set the window size and buffer (essentially scrolling inside the limitations of the window). This is really helpful to setup before hand since lines that are too long will word wrap if you don’t have a large window buffer. This will inevitably happen at some point and it’s really annoying when it does, so take steps to prevent it now.

If you find you navigate to a specific directory every time you open the shell, it may be a good idea to tell the app to navigate to that directory when you open the shell. In Terminal, this can be found at Preferences >> Settings >> Shell; in iTerm 2 this can be found at Preferences >> Profiles >> General. There are a lot of other cool features (like window groupings) that you should checkout.

Appearance

The next thing you’re going to want to do is customize your shell’s color. I like the traditional black background with white or light gray text and some colorful highlighting like green or even just a plain grey.

For my shell’s font, I like to use Monaco 10pt.  Smaller text let’s me see more on the screen since I usually only let my shell take up one half of the screen. I enable bold fonts and bright colors for bold fonts, but I disable anti-aliasing (smooth edges) because I like that raw hacker feel ;).

.profile, .bash_profile or .bashrc

Some of the most important customization takes place in the .profile file. Every time your shell loads, it will run the commands found in the “profiles.” There are a number profiles some system-wide (e.g. /etc/profile), others personal (e.g. .profile). The bash man page provides useful information about the differences under the “INVOCATION” section:

When bash is invoked as an interactive login shell, or as a non-
interactive shell with the --login option, it first reads and executes
commands from the file /etc/profile, if that file exists. After
reading that file, it looks for ~/.bash_profile, ~/.bash_login, and
~/.profile, in that order, and reads and executes commands from the
first one that exists and is readable. The --noprofile option may be
used when the shell is started to inhibit this behavior.

When a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash
reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if
these files exist. This may be inhibited by using the --norc option.
The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.

Then at the bottom of the man page:

FILES
       /bin/bash
              The bash executable
       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bashrc
              The systemwide per-interactive-shell startup file
       /etc/bash.bash.logout
              The systemwide login shell cleanup file, executed when a login shell exits
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file
       ~/.bash_logout
              The individual login shell cleanup file, executed when a login shell exits
       ~/.inputrc
              Individual readline initialization file

In essence, .bash_profile is read upon login and .bashrc is read for each new shell opened since you can have multiple shell sessions running at once without logging in again. In Mac OS X, the .bash_profile overrides the .profile. I’ve run into some problems with .profile in the past, so I’ve actually switched everything to .bash_profile.

The next four sections will discuss:

  • How to change prompt escapes (bash)
  • How to change prompt color (bash)
  • How to create your personal “bin”
  • How to create aliases

Change Prompt Escapes

First, I like to customize the prompte e. I can’t stand it when the prompt is white and blends in with the rest of the text in the shell. The appearance of the prompt is stored in the environment variable $PS1. Try typing echo $PS1 in your shell. The text you see is a string coded with the display setting for your shell’s prompt. It might look something like this:

\h:\W \u$

In this example, the \h represents the host computer, \W the working directory and \u the current user. All this information makes sense if you were to use the CLI a lot. “Back in the old days,” people would interface between various servers or computers over a network (esp. in business scenarios). When you’d change to a different server, you’d want to know the host computer you were accessing. Not all the computers had GUIs. Thus \h would let you know which computer you were on; whether you were on yours or another.

The \u is common for similar reasons. Sometimes you use the su command to substitute user and you’ll want to know which user you are acting as.

The \W should be self explanatory. You don’t want to have to type pwd or ls all the time to know where you are at in the file hierarchy.

In my prompt, I’ve gotten rid of the host symbol (I don’t switch hosts often and when I do, the other prompt is usually different enough that I can tell I’m on a different machine) and replaced it with the history number prompt escape (\!). This escape let’s you know which number in the command history you have just typed. That way if you see a previous command that you’d like to repeat a couple lines up you just type !<number>. To view your complete command history, type the command history. A simplified version of my prompt looks like this:

\! \u:\W$

Here’s a comprehensive list of prompt escapes to add to your prompt:

\a         # an ASCII bell character (07)
\d         # the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} # the format is passed to strftime(3) and the result
           # is inserted into the prompt string an empty format
           # results in a locale-specific time representation.
           # The braces are required
\e         # an ASCII escape character (033)
\h         # the hostname up to the first '.'
\H         # the hostname
\j         # the number of jobs currently managed by the shell
\l         # the basename of the shell's terminal device name
\n         # newline
\r         # carriage return
\s         # the name of the shell, the basename of $0 (the portion following
           #   the final slash)
\t         # the current time in 24-hour HH:MM:SS format
\T         # the current time in 12-hour HH:MM:SS format
\@         # the current time in 12-hour am/pm format
\A         # the current time in 24-hour HH:MM format
\u         # the username of the current user
\v         # the version of bash (e.g., 2.00)
\V         # the release of bash, version + patch level (e.g., 2.00.0)
\w         # the current working directory, with $HOME abbreviated with a tilde
\W         # the basename of the current working directory, with $HOME
           # abbreviated with a tilde
\!         # the history number of this command
\#         # the command number of this command
\$         # if the effective UID is 0, a #, otherwise a $
\nnn       # the character corresponding to the octal number nnn
\\         # a backslash
\[         # begin a sequence of non-printing characters, which could be used
           #   to embed a terminal control sequence into the prompt
\]         # end a sequence of non-printing characters

Change Prompt Color

To color code your prompt on a Mac, use the following template:

\[\033[COLOR_CODE_HERE\]PROMPT_ESCAPE_OR_TEXT_HERE\[\033[0m\]

Most Linux distributions use a little different format:

\e[COLOR_CODE PROMPT_ESCAPE\e[0m

The first portion before the desired prompt escape or text only begins painting the chosen color (e.g., \[\033[1;34m\]). To stop painting a color, you have to reset to another color or turn color off (e.g., \[\033[0m\]).

Here’s a comprehensive list of color encoding:

# Regular Colors
\[\033[0;30m\] # Black
\[\033[0;31m\] # Red
\[\033[0;32m\] # Green
\[\033[0;33m\] # Yellow
\[\033[0;34m\] # Blue
\[\033[0;35m\] # Purple
\[\033[0;36m\] # Cyan
\[\033[0;37m\] # White

# High Intensty
\[\033[0;90m\] # Black
\[\033[0;91m\] # Red
\[\033[0;92m\] # Green
\[\033[0;93m\] # Yellow
\[\033[0;94m\] # Blue
\[\033[0;95m\] # Purple
\[\033[0;96m\] # Cyan
\[\033[0;97m\] # White

# Background
\[\033[40m\] # Black
\[\033[41m\] # Red
\[\033[42m\] # Green
\[\033[43m\] # Yellow
\[\033[44m\] # Blue
\[\033[45m\] # Purple
\[\033[46m\] # Cyan
\[\033[47m\] # White

# High Intensty backgrounds
\[\033[0;100m\] # Black
\[\033[0;101m\] # Red
\[\033[0;102m\] # Green
\[\033[0;103m\] # Yellow
\[\033[0;104m\] # Blue
\[\033[10;95m\] # Purple
\[\033[0;106m\] # Cyan
\[\033[0;107m\] # White

#Replace any leading leading 0; with 1; for bold colors
#Replace any leading 0; with 4; to underline

Once you’ve decided on the appropriate prompt add export PS1=”<custom prompt>” to your .profile. For example, this is what the line in my .profile looks like:

export PS1="\[\033[1;34m\]\!\[\033[0m\] \[\033[1;35m\]\u\[\033[0m\]:\[\033[1;35m\]\W\[\033[0m\]$ "

Add Personal “bin” to the PATH Variable

Every now and again you may want to create your own custom commands, scripts or programs for the CLI. Instead of mixing these in with the rest of the OS’s, just create your own personal “bin” folder and add it to your PATH variable so that you can run those commands from any folder in the shell.

export PATH=$PATH:/Users/Taylor/bin

Create & Use Aliases

Aliases are really nifty. They can save you a lot of extra effort for frequently used and/or lengthy commands. For example, I found that I liked to use ls -lhaG a lot more than just ls as follows:

alias ls='ls -lhaG'

Alias long commands that you’d forget or never want to type. I use Git to version my code. The git log command is very powerful and can include a lot of options. Instead of typing the various options every time, I use an alias called glg:

alias glg='git log --date-order --all --graph --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'

Conclusion

At the end of the day, this is what my .bash_profile looks like:

UPDATED 2014-04-02

##################
### MY ALIASES ###
##################

# git command autocompletion script
source ~/bin/git-completion.bash

# git commamands simplified
alias gst='git status'
alias gco='git checkout'
alias gci='git commit'
alias grb='git rebase'
alias gbr='git branch'
alias gad='git add -A'
alias gpl='git pull'
alias gpu='git push'
alias glg='git log --date-order --all --graph --format="%C(green)%h%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'
alias glg2='git log --date-order --all --graph --name-status --format="%C(green)%H%Creset %C(yellow)%an%Creset %C(blue bold)%ar%Creset %C(red bold)%d%Creset%s"'

# ls alias for color-mode
alias lh='ls -lhaG'

# lock computer
alias lock='/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend'

# hibernation and sleep settings
alias hibernate='sudo pmset -a hibernatemode 25'
alias sleep='sudo pmset -a hibernatemode 0'
alias safesleep='sudo pmset -a hibernatemode 3'
alias smartsleep='sudo pmset -a hibernatemode 2'

# up 'n' folders
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'

# simple ip
alias ip='ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\ -f2'
# more details
alias ip1="ifconfig -a | perl -nle'/(\d+\.\d+\.\d+\.\d+)/ && print $1'"
# external ip
alias ip2="curl -s http://www.showmyip.com/simple/ | awk '{print $1}'"

# grep with color
alias grep='grep --color=auto'

# proxy tunnel
#alias proxy='ssh -D XXXX -p XXXX USER@DOMAIN'
# ssh home
#alias sshome='ssh -p XXXX USER@DOMAIN'

# processes
#alias ps='ps -ax'

# refresh shell
alias reload='source ~/.bash_profile'

###############################
### ENVIRONMENTAL VARIABLES ###
###############################

# Add homebrew sbin to PATH variable
export PATH=$PATH:/usr/local/sbin

# Add personal bin to PATH variable
export PATH=$PATH:/Users/Taylor/bin    # May be redundant; check ~/.bash_profile, /etc/profile, /etc/paths, /etc/bashrc

# Show dirty state in prompt when in Git repos
export GIT_PS1_SHOWDIRTYSTATE=1

# Change prompt
PS1_OLD=${PS1}
export PS1='\[\033[1;34m\]\!\[\033[0m\] \[\033[1;35m\]\u\[\033[0m\]:\[\033[1;35m\]\W\[\033[0m\] \[\033[1;92m\]$(__git_ps1 "(%s)")\[\033[0m\]$ '

What have you done to customize your shell or change your command prompt?

Compare Files Line-by-Line (or Image-to-Image)

Two of my favorite tools for line-by-line text comparison are diff and FileMerge. One reason why I like them so much is because they are lightweight alternatives for word processors like Microsoft Word, which you wouldn’t be inclined to open for coding (that’s one of my primary uses).

diff is a simple CLI-based tool accessible on most *nix systems. The basic format is diff <options> <file1> <file2>. It comes with a lot of powerful options too. To list a few:

  • Ignore tab expansion, blank lines, and other white space
  • Ignore case
  • Ignore matching lines
  • Side-by-side output
  • Compare files in directories
  • Recurse through subdirectories
  • Reporting identical files or simply whether or not differences exist

FileMerge is as simple as it gets for file comparison with a GUI. FileMerge comes with any installation of Xcode so it’s basically free. However, you’ll have to download the whole Xcode package (~1 GB) to get it unless you can find it floating around on the net alone.

FileMerge Screenshot

FileMerge allows you to select the changes you want to keep through a menu at the bottom-right that designates the favored document. By default, the right (as opposed to left) document is selected. Below the two separate documents is the final output that will result from the merge. FileMerge also allows you to edit/add content in this section before merging and saving.

As I was writing this post, I got a referral from Russ to a cross-platform comparison tool called Perforce. The cool thing about Perforce (besides being platform agnostic) is it compares not only files and folders, but images too. Not to mention it’s FREE. I only briefly read about it and watched some sample videos on the site, but it’s pretty powerful. It also can be used in parallel with Git. Read about it here.

After the recommendation to checkout Perforce, I started doing some more research and stumbled upon a couple other tools. First off, free code editor TextWrangler (Mac) includes file comparison. Diffmerge seems like a really cool alternative. It’s also free, available on multiple pllatforms and includes merging of 3 files and integration with Windows Explorer. Kaleidoscope is another option, though you’ll have to pay ~$40. It includes many of the same features as Perforce.

What do you use when you need to compare files? Have any recommendations?

Lock Your Screen on Mac

The Windows shortcut for locking the screen is pretty convenient (Windows Key + L). When you’re at work or a more public setting it’s nice to be able to lock your screen quickly before leaving your computer temporarily. In my searches to find a convenient way on Mac, I found a number of ways, many of which involve extra applications and menus in the menubar. I’ll briefly mention a few ways that may interest you, then mention the method I settled on.

One way is to add the Keychain Access menu to your menubar. To do this, Open Keychain Access (Cmd + Spacebar >> type Keych >> Enter) then open preferences (Cmd + ,) and check the first option to “Show keychain status in menubar.” Now you can lock the screen from the Keychain Access menu.

Keychain Access Menu

Another way is to enable the Fast User Switching menu. Do this by accessing System Preferences >> Users & Groups >> Login Options and then checking the option to “Show fast user switching menu as…” This will add a menu next to Spotlight and the clock allowing you to show the login window.

Fast User Switching Menu

While both of these methods are effective, they involve extra clutter in your menubar. So I’ve discovered two other easy ways that involve shortcuts. The first method uses the Screensaver Shortcut. To make this work, you’ll have to change your security settings such that your computer requires a password immediately after the screensaver starts. This can be done by navigating to System Preferences >> Security & Privacy. Check the first box and set the menu to “immediately”. Now all you have to do is key Ctrl + Shift + Eject. If you’ve done it correctly, you should be asked for a password as soon as you exit the screensaver via moving the cursor or pressing a key.

I prefer to have my screensaver come on relatively quickly (10-15 minutes) and I don’t like it when my computer asks me for a password immediately, so I went another route using Automator. It turns out you can control Fast User Switching from the command line using a binary called CGSession. CGSession takes two options (that I know of), namely -suspend and -switchToUserID <value>. Simply open Automator (Cmd + Spacebar >> type Autom >> Enter) and under the Utilities section find “Run a shell script” and drag it to the section on the right. Now copy and past the following script in the field where it says “cat” by default:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

Automator Screenshot

Be sure to change the menu for “Service receives” to “no input”. Now save this simple one step workflow as a service and call it something like “Lock Screen”. Now we are going to assign this service a global hotkey/shortcut. Navigate to System Preferences >> Keyboard >> Keyboard Shortcuts >> Services. At the very bottom, you should see a general service called “Lock Screen”. Make sure the box is checked and when you hover over it you should see a little button that says “Add Shortcut”. Click that and add a shorcut like Cmd + Alt/Opt + L. Now you should be able to lock your screen globally at any time.

System Preferences Keyboard Shortcuts

Alternatively, you could try using Quicksilver–a simple app that allows you to create powerful global shortcuts and the like. I used this before creating a service through Automator; however, I found it a bit cumbersome to use and setup. You shouldn’t need an extra app for something so simple.

Which way do you like best?

Mac OS X User Defaults

Defaults is a tool that allows Mac users to acces the user defaults system. It’s the tool used in my last two posts that allows you to make changes like hiding your desktop icons or showing hidden/invisible files. Since then, I’ve found a more comprehensive list of useful defaults.

To keep things simple, I’m going to refer you to a whole list of useful defaults posted by Github user mathiasbynens which he refers to as the dotfiles. I suggest you briefly read through it. Some other default changes you might be interested in are:

  • Enable key repeat in Lion
  • Enable 2D Dock
  • Enable iTunes track notifications in the Dock
  • Show all filename extensions
  • Disable automatic shadow in screenshots
  • Disable press-and-hold for keys in favor of key repeat
  • Set a blazingly fast keyboard repeat rate
  • Remove the auto-hiding Dock delay
  • Empty Trash securely

For your convenience, I’ve included the list below.

# Turn key repeat on in Lion (as opposed to selecting special characters)
defaults write -g ApplePressAndHoldEnabled -bool false

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

# Enable subpixel font rendering on non-Apple LCDs
defaults write NSGlobalDomain AppleFontSmoothing -int 2

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

# Automatically hide and show the Dock
defaults write com.apple.dock autohide -bool true

# Make Dock icons of hidden applications translucent
defaults write com.apple.dock showhidden -bool true

# Enable iTunes track notifications in the Dock
defaults write com.apple.dock itunes-notifications -bool true

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

# Show remaining battery time; hide percentage
defaults write com.apple.menuextra.battery ShowPercent -string "NO"
defaults write com.apple.menuextra.battery ShowTime -string "YES"

# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"

# Allow quitting Finder via ⌘ + Q; doing so will also hide desktop icons
defaults write com.apple.finder QuitMenuItem -bool true

# Disable window animations and Get Info animations in Finder
defaults write com.apple.finder DisableAllAnimations -bool true

# Show all filename extensions in Finder
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

# Show status bar in Finder
defaults write com.apple.finder ShowStatusBar -bool true

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

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

# Disable the “Are you sure you want to open this application?” dialog
defaults write com.apple.LaunchServices LSQuarantine -bool false

# 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 com.apple.dock enable-spring-load-actions-on-all-items -bool true

# Show indicator lights for open applications in the Dock
defaults write com.apple.dock show-process-indicators -bool true

# Don’t animate opening applications from the Dock
defaults write com.apple.dock launchanim -bool false

# Remove the auto-hiding Dock delay
defaults write com.apple.Dock autohide-delay -float 0

# Display ASCII control characters using caret notation in standard text views
# Try e.g. `cd /tmp; unidecode "\x{0000}" > cc.txt; open -e cc.txt`
defaults write NSGlobalDomain NSTextShowsControlCharacters -bool true

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

# Set a blazingly fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 0

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

# Disable opening and closing window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

# Enable AirDrop over Ethernet and on unsupported Macs running Lion
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true

# 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
defaults write com.apple.finder OpenWindowForNewRemovableDisk -bool true

# Display full POSIX path as Finder window title
defaults write com.apple.finder _FXShowPosixPathInTitle -bool true

# Increase window resize speed for Cocoa applications
defaults write NSGlobalDomain NSWindowResizeTime -float 0.001

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

# Disable the warning when changing a file extension
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

# Show item info below desktop icons
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:showItemInfo true" ~/Library/Preferences/com.apple.finder.plist

# Enable snap-to-grid for desktop icons
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist

# Disable the warning before emptying the Trash
defaults write com.apple.finder WarnOnEmptyTrash -bool false

# Empty Trash securely by default
defaults write com.apple.finder EmptyTrashSecurely -bool true

# Require password immediately after sleep or screen saver begins
defaults write com.apple.screensaver askForPassword -int 1
defaults write com.apple.screensaver askForPasswordDelay -int 0

# Enable tap to click (Trackpad)
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true

# Map bottom right Trackpad corner to right-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -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 IncludeInternalDebugMenu -bool true

# Make Safari’s search banners default to Contains instead of Starts With
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false

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

# Add a context menu item for showing the Web Inspector in web views
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true

# Enable the debug menu in Address Book
defaults write com.apple.addressbook ABShowDebugMenu -bool true

# Enable the debug menu in iCal
defaults write com.apple.iCal IncludeDebugMenu -bool true

# Only use UTF-8 in Terminal.app
defaults write com.apple.terminal StringEncodings -array 4

# Disable the Ping sidebar in iTunes
defaults write com.apple.iTunes disablePingSidebar -bool true

# Disable all the other Ping stuff in iTunes
defaults write com.apple.iTunes disablePing -bool true

# Make ⌘ + F focus the search input in iTunes
defaults write com.apple.iTunes NSUserKeyEquivalents -dict-add "Target Search Field" "@F"

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

# Copy email addresses as `foo@example.com` instead of `Foo Bar ` in Mail.app
defaults write com.apple.mail AddressesIncludeNameOnPasteboard -bool false

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

# Disable the “reopen windows when logging back in” option
# This works, although the checkbox will still appear to be checked.
defaults write com.apple.loginwindow TALLogoutSavesState -bool false
defaults write com.apple.loginwindow LoginwindowLaunchesRelaunchApps -bool false

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

# Reset Launchpad
[ -e ~/Library/Application\ Support/Dock/*.db ] && rm ~/Library/Application\ Support/Dock/*.db

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

# Disable local Time Machine backups
hash tmutil &> /dev/null && sudo tmutil disablelocal

# Remove Dropbox’s green checkmark icons in Finder
file=/Applications/Dropbox.app/Contents/Resources/check.icns
[ -e "$file" ] && mv -f "$file" "$file.bak"
unset file

# Fix for the ancient UTF-8 bug in QuickLook (http://mths.be/bbo)
# Commented out, as this is known to cause problems when saving files in Adobe Illustrator CS5 :(
#echo "0x08000100:0" > ~/.CFUserTextEncoding

# Kill affected applications
for app in Safari Finder Dock Mail SystemUIServer; do killall "$app" >/dev/null 2>&1; done

Which ones did you find most useful? Have any to add to the list?