Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Launch iPhoto only on camera, not iPhone, connect iPhone
I have been continually annoyed with the way that iPhoto would start whenever I plugged my iPhone into my computer. The only pictures I take with my iPhone are to help me find my space in a parking lot, or so I can reassemble something I am taking apart. I do not want to archive these pictures. However, I do still want to use iPhoto to take the pictures off my digital camera. My previous solution was to set Image Capture to disable launching iPhoto in every case of camera attachment, and then manually launching iPhoto when necessary.

Luckily, Sam Stephenson at 37signals provided me with a solution that will launch iPhoto when a camera is attached, but not when my iPhone is attached. Sam realized that within the preference pane of Image Capture, an arbitrary application can be set to launch whenever a camera is connected. This solution utilizes the shell command ioreg combined with grep to search through the USB devices connected to the computer.

The script is able to sort through the connected devices and see if a specific device is connected. If that device is connected, iPhoto will be launched. Since the application is set to run whenever a camera is connected, it provides a method of sorting between the iPhone and a digital camera. Sam does a really great job of explaining every step for those not proficient with the terminal or scripts.

While this is quite useful as is, I wanted a slightly more generic form. I wanted to launch iPhoto for every camera that was connected, but never for my iPhone. Instead of searching the I/O Kit registry for a specific camera, I decided to search for any entry containing the word Camera.

My first plan was to just edit Sam's script such that it would look for the word Camera and when found, launch iPhoto. That code looks like this:
--initialize variable to a known value
set cameraName to "0"

-- perform script to see if there is any attached USB
-- device that has the word "Camera" in its name
try
  set cameraName to ¬
   (do shell script "ioreg -Src IOUSBDevice | grep 'Camera'")
end try

-- if there is a camera attached, start iPhoto
if length of cameraName is greater than 6 then
  activate application "iPhoto"
end if
Upon realization that grep throws an error if it cannot find what it is searching for, I decided to attempt a minimalist script. Below is a version that is slightly less intelligible by utilizing try to perform the logic.
try
  do shell script "ioreg -Src IOUSBDevice | grep 'Camera'"
  activate application "iPhoto"
end try
This works because if grep throws an error (i.e. the word Camera wasn't found), then the try routine is terminated before the activate... line is reached.

After copying/pasting either of these scripts into Script Editor and saving as an application, one can go to the Preferences in Image Capture and set this application to open when a camera is connected. This can be done by clicking on Other in the drop down menu, then selecting the application that was just created. Image Capture is located in the Applications folder.

I was even able to snag a snazzy icon from within the iPhoto 6 bundle to make my script look a little more professional. By control-clicking on iPhoto.app, choosing Show Package Contents and navigating to Contents » Resources, I found an image I like called import_camera.tiff. This can be set as the icon for the application by first opening import_camera.tiff in Preview and copying it to the clipboard (Command-C). Next, click on the application and bringing up the Get Info window by pressing Command-I. The process is completed by selecting the generic script icon in the upper left (with a click) and pasting the clipboard contents (Command-V) over the top.

This works well for me, but you might find Sam's specific method much more useful -- it depends on your situation. Both methods have issues when the camera and iPhone are connected at the same time.

[robg adds: This worked as described (both versions) in my testing.]
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[15,921 views]  

Launch iPhoto only on camera, not iPhone, connect | 8 comments | Create New Account
Click here to return to the 'Launch iPhoto only on camera, not iPhone, connect' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Launch iPhoto only on camera, not iPhone, connect
Authored by: benzado on Mon, Mar 10 2008 at 10:12AM PDT
As I already noted in a comment on the 37signals blog, I wrote a variant of the script that works for any camera and does not have issues if you connect an iPhone when a camera is already connected, or vice versa.

http://benzado.livejournal.com/240117.html

[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: leamanc on Mon, Mar 10 2008 at 8:30PM PDT
Thanks, this is just what I was looking for! I plug my iPhone into my work laptop occasionally when I'm low on power. It's always annoyed me to have to quit iPhoto every time.

In fact, I had just got done quitting iPhoto today when I noticed this hint come up on my iGoogle page's OS X Hints widget. Perfect timing!

[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: bcometa on Wed, Mar 19 2008 at 9:44AM PDT
"try
do shell script "ioreg -Src IOUSBDevice | grep 'Camera'"
activate application "iPhoto"
end try"

brilliant hint Sam & darick! exactly what I needed and works seamlessly in the background so you really never have to know it's there. fyi to anyone considering this... you can still just open iphoto with iphone attached to download iphone photos.
thanks!!
-brian
corewerkz

[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: lokon1979 on Wed, Apr 16 2008 at 11:41PM PDT
in fact, if you don't have any photos in your iPhone's camera roll (that is, those you took with your iPhone), iPhoto won't auto launch.

so if every time iPhoto auto launch with your iPhone plug in, just import all the photos into iPhoto and empty the iPhone's camera roll. you can put those photos into an album in iPhoto (even better make a smart album), and sync them back with iTunes. iPhoto won't auto launch with synced photo albums, but only if you have any photos in iPhone camera roll.

[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: quella on Thu, Apr 17 2008 at 11:21AM PDT
I'm wondering id this can be done with a NOT <> iPhone to launch iPhoto. My wife and I often do not plug in the camera direcly, we take the card out and place it in our card reader hooked up to the iMac's USB. When I followed the above script, iPhoto only auto launched for the camera and not the flash. It would be nice to saw that iPhoto should launch when NOT an iPhone not when there is a camera. I will need to do some work on this. Great place to start from. Thanks for sharing.

Quella

[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: PeterDie on Sat, Aug 2 2008 at 2:26PM PDT
With two brands of camera's, I have the same problem. I don't use a cardreader, but a NOT option would be nice. But you can work around this by piling it up, one rule after another, with the name of your cardreader as GREP option for you.

My script looks like this:

try
do shell script "ioreg -Src IOUSBDevice | grep 'NIKON'"
activate application "iPhoto"
end try
try
do shell script "ioreg -Src IOUSBDevice | grep 'Kodak'"
activate application "iPhoto"
end try
--- And just to be on the save side or guest camera's
try
do shell script "ioreg -Src IOUSBDevice | grep 'Camera'"
activate application "iPhoto"
end try




[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: PeterDie on Sat, Aug 2 2008 at 2:50PM PDT
Oh, and by the way, this script also is a nice way to start up the right app, pro and amateur:

try
do shell script "ioreg -Src IOUSBDevice | grep 'NIKON'"
activate application "Aperture"
end try
try
do shell script "ioreg -Src IOUSBDevice | grep 'Kodak'"
activate application "iPhoto"
end try


[ Reply to This | # ]
Launch iPhoto only on camera, not iPhone, connect
Authored by: toddself on Tue, Sep 1 2009 at 5:14AM PDT
So. I just upgraded to Snow Leopard, but since this script was originally compiled with Leopard's AppleScript editor it was actually a PowerPC app. Since Rosetta is no longer installed it kept prompting me to install Rosetta, but eh, I'd rather not.

So I went and recompiled it and then opened Image Capture in Snow Leopard. But woah.

Image Capture now lets you set a specific action PER DEVICE. You no longer need to do anything like this. Totally revamped. Awesome.

[ Reply to This | # ]