Change hostname in OS X

The hostname you initially chose for your Mac gets used in various ways; as a friendly identifier for the user, file sharing, command line networking  and services like AirDrop. Although you can change the computer name used for file sharing in the System Preferences GUI, that’s only used for file sharing. To update the hostname across the board, you need to issue the following three commands, followed by a reboot for good measure.

ComputerName is the name shown to the user in most of the GUI, and is used for things like AppleTalk and Windows file sharing.

sudo scutil --set ComputerName "my-laptop"

HostName is the name that you’ll be using at the terminal and for networking, as reported by the hostname command.

sudo scutil --set HostName "my-laptop"

LocalHostName is used for Bonjour services.

sudo scutil --set LocalHostName "my-laptop"

Remember to reboot to make sure changes take effect.

Stop Android File Transfer application auto-starting on OS X

TL;DR: If you’re not interested in following the steps one by one, jump straight to the command line solution.

If you’ve installed the Android File Transfer application for OS X, you’ll find it automatically starts each time you connect your Android device to your Mac. This behaviour is fine if you only connect your Android device to your Mac for the purpose of transferring files, but it becomes a bit of a nuisance when you just want to charge your device or use it for development purposes.

There’s no setting within the app to disable auto-starting so you need to manually disable the agent that ‘listens’ for Android device connections. Here’s how to do that.

  • Open Activity Monitor and quit the ‘Android File Transfer Agent’ process.
  • Open the Applications directory within Finder.
  • Ctrl-click (or right-click) ‘Android File Transfer.app’ and select ‘Show Package Contents’.
  • Drill down into the ‘Contents/Resources’ directory.
  • Rename ‘Android File Transfer Agent.app’ to something like ‘Android File Transfer Agent DISABLED.app’.
  • Navigate to the ‘~/Library/Application Support/Google/Android File Transfer’ directory in Finder (you may need to hold down ‘alt’ within Finder’s ‘Go’ menu to see ‘Library’).
  • Again, rename ‘Android File Transfer Agent.app’ to something like ‘Android File Transfer Agent DISABLED.app’.

Edit (8th January 2013): The above worked well for me until some time around the start of the new year, probably tied in with my Mac updating to OS X Mavericks. Now, an additional step is required to keep the agent from auto-starting, and is included in the following instructions.

  • Open the Users & Groups panel in System Preferences, and remove any entry for ‘Android File Transfer Agent’ in your user’s ‘Login Items’.

Done! You can still manually start the Android File Transfer application (as you would for any other application) but now there’s no more auto-starting.

If you want to re-enable auto-starting at a later date, simply rename the two app files back to their original names and manually start the Android File Transfer application to kick start the agent again.

If you’re feeling especially geeky, you could achieve the same thing from the command line. Here’s a not-so-pretty one liner that will kill the agent process if it’s running, rename the two agent .app files, and remove the agent from your user’s ‘Login Items’.

PID=$(ps -fe | grep "[A]ndroid File Transfer Agent" | awk '{print $2}'); if [[ -n $PID ]]; then kill $PID; fi; mv "/Applications/Android File Transfer.app/Contents/Resources/Android File Transfer Agent.app" "/Applications/Android File Transfer.app/Contents/Resources/Android File Transfer Agent DISABLED.app"; mv "${HOME}/Library/Application Support/Google/Android File Transfer/Android File Transfer Agent.app" "${HOME}/Library/Application Support/Google/Android File Transfer/Android File Transfer Agent DISABLED.app"; osascript -e 'tell application "System Events" to delete every login item whose name is "Android File Transfer Agent"'

Improve Dock responsiveness on OS X when auto-hide is enabled

If you have the Dock set to automatically hide and show, you will have probably noticed that there’s a small but perceptible delay between it being triggered and it actually appearing. This is by design, to make it more difficult to trigger by accident, but when you need to flick between items in the dock frequently, those wasted milliseconds can become quite annoying very quickly.

There aren’t any options to control the dock delay from within the System Preferences but it is very easy to adjust via the command line. The following commands will work on OS X 10.7 (Lion) or newer.

The setting to control the delay is called autohide-delay and its value is specified in seconds. Personally, I have this set to 0 so that it’s instantaneous but you can set it to whatever you like by changing 0 in the following command to your desired value. The default is probably around 0.3.

defaults write com.apple.Dock autohide-delay -float 0
killall Dock

To restore the default delay:-

defaults delete com.apple.Dock autohide-delay
killall Dock

In addition to reducing the delay, you can speed things up further by specifying the duration of the Dock animation. This setting, called the autohide-time-modifier, is also specified in seconds. A value of 0 is instantaneous (no animation). I like a value of 0.4 which makes the dock feel very snappy whilst still looking pretty slick.

defaults write com.apple.Dock autohide-time-modifier -float 0.4
killall Dock

To restore the default duration:-

defaults delete com.apple.Dock autohide-time-modifier
killall Dock

All settings take effect as soon as you kill the dock (it will automatically reload) so it’s easy to experiment with different values until you find what works for you.