Benjamin Ragheb (benzado) wrote,

Re: Tip: Prevent iPhoto from opening when you plug in your iPhone

A post by Sam on 37signals explains how to write a script so that iPhoto will automatically launch when you plug in your camera but not your iPhone. Sam's script checks the list of USB devices connected to the system and only launches iPhoto if your camera is connected. That method doesn't work so well if you use a USB card reader, since it appears in the list as "USB Storage Device", the same name given to any USB disk. Using Sam's method, iPhoto would open if I connected my iPhone while I had any USB disk connected to my computer.

To overcome this problem, I wrote a new script that finds the name of the last USB device connected, which presumably is the device that triggered the system to execute the script. The script launches iPhoto except when the last device connected is an iPhone. Here is the source:

on get_device_name()
    set list_devices to "ioreg -Src IOUSBDevice | grep '^\\+'"
    set get_name_of_last to "tail -n 1 | sed 's/^\\+-o \\(.*\\)@.*/\\1/'"
    set command to list_devices & " | " & get_name_of_last
    return (do shell script command)
end get_device_name

on run
    if get_device_name() is not equal to "iPhone" then
        tell application "iPhoto" to activate
    end if
end run


Paste that into Script Editor, save it as an application, then go to the Image Capture preferences and set the script application to be launched whenever a camera is connected. You don't need to do all the Terminal stuff that Sam requires in his post because we don't need to know your camera's USB name.

P.S. The comments on the original post make for a fascinating case study in people aggressively missing the point.
  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded  

  • 12 comments