I love that OS X automatically fires up iPhoto when I plug in my digital camera. It’s one of the Mac’s many little touches that make it such a pleasure to use.

But ever since I got an iPhone, I’ve been frustrated that plugging it in opens up iPhoto, too. The combination of iPhoto and iTunes opening and syncing slows my computer to a crawl. And it’s particularly painful when most of the time I just want to sync my address book or music.

Fortunately it’s pretty easy to work around this annoyance. Keep reading to see how you can teach your Mac to open iPhoto when you plug in your camera but not your phone.

I recently stumbled across an option in Image Capture’s preferences that lets you select any application to open when a camera is connected. That gave me an idea: what if I could tell it to open a special application that would check to see which camera I’d plugged in? Then that application could in turn open iPhoto only if I’d plugged in my Digital Rebel.

It turns out you can do all of this using the command line and a little bit of AppleScript. Here’s how:

1. Set up the script

Open Script Editor (in the AppleScript folder inside your Applications folder). Copy and paste this script into the editor window:

on device_is_connected(device_name)
  set check_for_device to "ioreg -rn " & quoted form of device_name
  return (length of (do shell script check_for_device) is not equal to 0)
end device_is_connected

on run
  if device_is_connected("") then
    tell application "iPhoto" to activate
  end if
end run

2. Get a list of all the USB devices connected to your computer

Keep Script Editor running, and open Terminal (in the Utilities folder inside your Applications folder). Copy and paste this command into the terminal window:

ioreg -Src IOUSBDevice | grep '^\+' > /tmp/ioreg

This command lists all the USB devices connected to your computer and stores the list in a temporary file.

3. Find OS X’s name for your camera

Plug in your digital camera and turn it on. Then copy and paste another command into the terminal window:

ioreg -Src IOUSBDevice | grep '^\+' | diff /tmp/ioreg - |
  tail -1 | sed 's/^> \+-o \(.*\)@.*/\1/' | pbcopy && pbpaste

This command again lists all the USB devices connected to your computer and compares it with the previous list you saved to a temporary file. Then it extracts the name of the camera you just plugged in. You should see this name displayed in the terminal (for example, when I plug in my Digital Rebel XT, I see Canon Digital Camera). It’ll be copied to your clipboard, too.

4. Insert the camera’s name into the script

Quit Terminal and switch back to Script Editor. Find the line that reads:

    if device_is_connected("") then

Place the cursor between the two quotes and choose Paste from the Edit menu, so that you see your camera’s name in the quotes, like this:

    if device_is_connected("Canon Digital Camera") then

Make sure there’s no line break between the camera name and the last quote mark.

You can also change “iPhoto” on the next line to “Aperture” or “Lightroom”, if you’d prefer to open one of those applications instead.

5. Save the script as an application

Choose “Save As…” from the File menu, pick “Application” in the “File Format:” dropdown, and save the script as “Camera Connected” in your Applications folder.

6. Set the application to run when you connect your camera

Quit Script Editor and open Image Capture (in your Applications folder). Choose “Preferences…” from the Image Capture menu and pick “Other…” in the “When a camera is connected, open:” dropdown. Then select the “Camera Connected” application you just created.


Next time you connect your camera iPhoto will open, and when you connect your phone it won’t.

(Confused? Watch a QuickTime demo of the steps above.)