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

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.

  • 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.

Fix EXIF dates and times with Jhead

My parents recently returned from several weeks of travelling and brought back with them, a couple of thousand photos taken using two different cameras. We wanted to merge the photos from both cameras in to one directory so they could be viewed in chronological order, but soon realised the EXIF date and times were incorrect due to both cameras having their internal clocks incorrectly set.

Modifying the EXIF data in photos is pretty easy – a lot of image viewing / editing apps will let you do this, but usually on a one by one basis. That’s a lot of pain for adjusting ~2,000 photos! A quick Google search turned up a selection of apps that looked like they would do the job but I settled on Jhead because it works from the command line and is available from Ubuntu’s standard repositories. There are also Windows and OS X binaries available if you’re using either of those platforms.

Installing Jhead

Jhead’s been around for over a decade so if you’re using Linux, it’s most likely in your distro’s repositories. For Windows and OS X you can download it from here.

On Ubuntu, installing Jhead is as easy as:-

sudo apt-get install jhead

Or if you’d prefer, just search for ‘Jhead’ from the graphical package manager.

Modifying the EXIF Date and Time

Firstly, you need to work out how much time you need to adjust your photo’s EXIF data by in order to correct them. Because the photos I was working with came from two different cameras, each with a different date and time set, I separated them in to two directories and did this for each.

A full summary of Jhead’s command line arguments can be found here but for most purposes there are only two options we need to make use of, one for adjusting the time by a specified offset and one for adjusting the date.

To adjust the time, we use the -ta option followed (without space) by the offset to use in hh:mm or hh:mm:ss format. If, for example, your photo’s times are set 1 hour too far in to the future, we can subtract a single hour from all photos using the following.

jhead -ta-1:00 *.jpg

If the photos were set 12 hours, 20 minutes and 43 seconds too far in the past, we’d offset with a positive value.

jhead -ta+12:20:43 *.jpg

For offsets greater than 24 hours, we can use the -da option followed by two dates in yyyy:mm:dd format, or to include a time, as yyyy:mm:dd/hh:mm:ss. Because years and months have different numbers of days, rather than specifying an offset, we actually specify two dates for this option – the first being the date to translate to, relative to the second.

So if a particular photo was taken on the 29th February 2012 at 8:21am, but the camera recorded it as the 1st January 2000 at 2:24pm, we would use the following.

jhead -da2012:02:29/08:21-2000:01:01/14:24 *.jpg

It doesn’t matter that the photos weren’t all taken at the very same time specified by either date in this argument, Jhead will just work out the correct offset to use from the before and after dates and apply it correctly to each photo individually.

Setting the File System’s Timestamp

This is not strictly necessary but can be useful if you want your file system’s file creation dates to now match those of the newly fixed EXIF dates.

jhead -ft *.jpg

Additonal Options

Jhead can also perform some other useful tasks such as image rotation in accordance with the image’s orientation tag, extracting camera settings, displaying embedded GPS info, etc. Check out it’s full list of command line options to learn more.