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.
Done!
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.)
Kyle Pike
on 20 Feb 08Now that is eerie. I was just wondering if this was possible as I docked my iPhone and headed over to catch up on the blog. Quick Sam, what number am I thinking of?
J
on 20 Feb 08God forbid Apple put in a checkbox you could toggle in your iPhoto preferences or something like that.
Mariano
on 20 Feb 08Mmmm. In Windows all that just require a couple of clicks :) You can choose the software to be used (or not) when you connect your device… (And I use MacOS X too).
Beerzie
on 20 Feb 08I’m with J. I should be able to do this without a hinky workaround.
Michael Puhala
on 20 Feb 08Even easier is to make iPhoto not open in iPhoto Preferences (in the ‘General’ section) when a camera is connected. While not nearly as elegant as described by Sam in the above post, it’s a quick way for iPhoto not to open when any camera is connected. It’s just as easy to open iPhoto yourself once the camera is connected.
waltkania
on 20 Feb 08Hmm. All I do is go use the “Photos” tab in iTunes.
When your iPhone appears in the Devices List, click the iPhone. Go to the Photos Tab, then UN-check “Synch Photos with . . .” Even with new photos on the iPhone, it won’t launch iPhoto when you dock the phone.
Or am I stupidly missing something?
Jean
on 20 Feb 08I find this post strange… 37s is advocate of simplicity. And now we get a high tech wizz advise to mod my iphone? After the Backpack news of yesterday this is VERY strange !
I know the blog (web developers) readers love these scripts but I have to deal with people that like the Iphone and 37s because its simple.
How can I motivate them to read this blog ?
DHH
on 21 Feb 08Jean, I don’t think I understand your concern? We write for a wide audience comprised of many niches. Some like techy stuff like this others like posts about design others again about business decisions. You don’t need to read, do, grok everything we write to enjoy the things you do understand.
SS
on 21 Feb 08waltkania, this method lets you keep iPhoto albums synced with your iPhone. (iTunes will do this silently without starting iPhoto.) The difference is that you will not be prompted to import photos from your phone every time you sync it. And if you do want to import your phone’s photos you can just launch iPhoto manually.
I’ve found that I want to import photos from my phone maybe 5% of the times it’s plugged in, whereas I want to import photos from my camera every time I plug it in.
J Lane
on 21 Feb 08Sam, you’re hands down my hero for the day. Thanks a bunch for this, Aperture launching every time I docked my phone was starting to drive me nuts.
J Lane
on 21 Feb 08I should probably share one last thing, I had to do a little modification because I use a USB Flash card reader, instead of hooking my camera up to my computer. So I changed Sam’s script to look for the iPhone if it’s connected, and if it is, do nothing, otherwise launch, in my case Aperture. The mod looks like this:
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(“iPhone”) then else tell application “Aperture” to activate end if end run
Nate Klaiber
on 21 Feb 08I did it by connecting my iPhone, opening Image Capture from applications, then selected to not open iPhoto when it is connected.
Ian
on 21 Feb 08Sam, Nate… you guys are awesome. iPhoto opening every single time I docked it was annoying as all hell. I couldn’t believe Apple let that go by as default behavior for the phone.
blazingice
on 21 Feb 08Wouldn’t it be easier to blacklist the iPhone itself? Just change the line: if device_is_connected(””) then to
if not device_is_connected(“iPhone”) then
and things work out just fine, without the command line magic. You also won’t have to change the script when you buy a new camera later!
Matt Radel
on 21 Feb 08Sam, you the man! This has been the single biggest gripe I’ve had with the iPhone and its integration with OSX. Thanks SO much for the tip!
Joshua Kaufman
on 21 Feb 08Does it strike anyone else as ridiculous that we have to run a script to keep annoying things from happening on our Mac? Part of what has made Apple great is that they start with the basics and then you can turn advanced things on – if you want them. Unfortunately, they’ve made it terribly difficult to do nothing by default for a while now. This kind of behaviour is just rude and needs to stop.
Nate Klaiber
on 21 Feb 08@Joshua Kaufmann You don’t need a script, he just chose to write one for it. You can see another solution above using Image Capture (on every mac), and then selecting to not open iPhoto.
SS
on 21 Feb 08blazingice, good point. But using that technique, if you plug in a camera while your phone is plugged in to charge, iPhoto won’t open. Although that’s admittedly somewhat of an edge case ;)
SS
on 21 Feb 08Joshua, I actually find it quite nice that even though Apple doesn’t provide an interface for changing this preference per-camera, they 1) leave the option open for third parties to easily hook into the “camera connected” event and 2) provide all the tools necessary to do it yourself with a base OS X install (you don’t even need the developer tools).
And as Nate says, you certainly don’t “have to run a script to keep annoying things form happening” – you can prevent iPhoto from opening up altogether with just a couple of clicks (Preferences > Connecting camera opens: No application).
Dave
on 21 Feb 08“Fortunately it’s pretty easy to work around this annoyance”
You’re kidding right?
Imagine if you had to do this on a Windows box. You’d have all the Apple fanboys pointing it out as yet another reason why Microsoft are the worst OS company in the world. “I have to do all that just to stop that stupid app from launching!”
As Mariano pointed out, this only takes a couple of clicks to do under Windows.
Joshua Kaufman
on 21 Feb 08Hey, you got me. I guess I’m just still bitter that iTunes and Finder don’t provide the option to do nothing for a task as common as inserting a blank CD. (Granted, those screenshots were taken in Panther; I’m not sure if it’s still the same in Leopard.) Sorry, for firing off.
Nate Klaiber
on 21 Feb 08@Joshua Kaufman All of the CD/DVD stuff is in System Preferences. There you can control what happens when you insert a CD/DVD. It makes sense there (as you may not want to use iTunes for anything – so iTunes shouldn’t hold the options for CDs/DVDs).
I do wish they would switch default browser stuff out of Safari though (why isn’t that in system preferences?).
Jose
on 21 Feb 08People…Sam is just trying to give us a solution…calm down…
Adrian Parker
on 21 Feb 08My crusty old HP laptop fires up Canon PhotoBrowser when I plug in my digital camera, and fires up Nokia phone browser when I plug in my phone, and fires up Panasonic photo software when my beloved plugs in here camera, so….
doesn’t this mean Mac’s are kind of a long long way behind? :-)
Sebhelyesfarku
on 21 Feb 08Apple – just works.
Keith
on 21 Feb 08Neat tip Sam. I don’t have an iPhone, but this is a great example of the power and customization that is possible on an Apple that many people don’t realize.
Mike
on 21 Feb 08@ Keith this is a great example of the power and customization that is possible on an Apple that many people don’t realize.
Yeah, many people don’t realize it because a vast majority of people out there don’t have the ability to implement what is in this post. Apple should make this process a checkbox, not a 6 step process someone had to Google the web for.
Like Dave says above, if this was a Windows workaround, Macfans would be snickering and complaining about having to jump thru these hoops to implement a simple process.
Matt Radel
on 21 Feb 08I agree that this should be put into a neat little checkbox somewhere, and I was quite frankly surprised when I couldn’t find one.
But to be perfectly honest, I think Apple might be growing a shade too fast. It doesn’t seem like they’re putting quite the same level of detail and attention into some things as they used to.
sirstaunch
on 21 Feb 08Something that Apple has over looked, although the fix is simple, maybe they will listen and implement this in an upgrade ;)
addicted
on 21 Feb 08The reason Windows makes this easier (although it really does not, since this still syncs the phone, which the windows option would not) is because Windows presents you with every option under the roof. A good thing about Apple is that it only presents the most needed options. As a compromise, they allow you to use the terminal, or scripts to work around stuff that they may not have given an option for. When you make hard choices about what to leave out, sometimes you can also make bad choices.
If this turns out to be a major issue for people (I dont have an iphone) then they will certainly add a fix in the future. In the meanwhile, I am happy with an OS that reduces my mental stress by limiting my easily available options, but still allows me to do whatever the hell I want, if I am really annoyed by it.
By the way, if you want to look up windows annoyances, go to xpannoyances.com (Vista doesnt count as an OS until SP1 is released). See the number you have to hack the registry for and that should quell the complaining for a while.
Emily
on 21 Feb 08And you’re doing what, Mike? It sure seems like snickering to me. How is this different? Some folks are grateful for the information, and some folks are snickering.
Looks like you got exactly what you wanted.
Christopher Fahey
on 21 Feb 08Sam, I just want to commend you on your excellent instructions-writing skills. You didn’t assume the user was already an expert user of Terminal or AppleScript, so you didn’t leave out critical steps which would have been obvious to such people. These sorts of omissions explain why 99% of these sorts of “cool tips” end up either alienating potential users or causing people to screw up their systems. Nice work.
Peter
on 21 Feb 08Nate, the default browser preference was in System Preferences. I believe it was in 10.2 when the .mac panel was actually an internet panel.
Gedeon Maheux
on 21 Feb 08The way I get iPhoto not to launch every time I plug in my iPhone is to download and delete the images in the camera app. I then sync them back and the next time iPhone won’t automatically launch. Done and done.
Bruce
on 21 Feb 08This is a nice hack. I think that blazingice has a good point. If you make a script that excludes iPhone, it doesn’t need to be customized for each camera. You could publish this script on macsripters and macupdate and a wide variety of people could use it easily. You’d get a lot more fame and glory that way. ;-)
Jean
on 21 Feb 08@DHH
You are right, I was over reacting. I was just trying to advocate your blog and the new Backpack to my team. In the heat off the moment I got a bit to excited. Next time I will think twice ;-) Thank you
mark
on 21 Feb 08always funny to see the gaylord apple fuckboys trying to justify the shitty products apple puts out
Michael K
on 21 Feb 08Another edge case that the provided script doesn’t account for:
Plug in your camera
iPhoto launches
Import photos
Quit iPhoto but leave camera plugged in
Plug in iPhone
iPhoto will launch again in this case (because iPhoto launched the script, and the script detected the presence of the camera), and that’s probably not the desired effect. Applescript has no way of knowing what the device was that triggered the script, so there’s no way to make it completely bulletproof.
Apple really should have provided a per-device option on this.
That said, it’s a slick solution, and I commend you for it. :)
Michael K
on 21 Feb 08Looking more closely at the output from ioreg, you might be able to use the sessionID property to determine which device was plugged in most recently. I just played with plugging and unplugging a few devices, and the one added most recently always has the highest sessionID. So unless you intentionally trigger a race condition by plugging both devices in at once (in which case you deserve what you get), it seems there is a way to tell which of your iPhoto-philic devices triggered the script.
Anwar
on 21 Feb 08can you not just put an ‘if NOT’ in the applescript, and then the device name as iPhone. I dont actually have another digital camera to test it out with, so apologies if its not right. This is the script I use: on run if not device_is_connected(“iPhone”) then tell application “iPhoto” to activate end if end run
Brian Mikol
on 21 Feb 08While I do agree that it would be best for Apple provide a per-device checkbox solution, we’ll never know when/if that would happen. In the meantime, thanks much for the effort and sharing it here! Looking forward to implementing it as soon as I get home.
iJosh
on 21 Feb 08For all of those syaing you should be able to do this without any kind of workaround. I have this to say to you: http://www.apple.com/feedback
They don’t have time to read every blog about them and troll the internet on tiny little improvements they could make. I do however firmly believe that apple watches the unsolicited feedback as there is a feature that was added in 1.1.2 iPhone firmware and the iTunes update that surrounded it that I wrote indepth about. Provided a reasoned argument about the feature. Do that and they will listen.
Mark
on 22 Feb 08First of all, Sam, thanks for providing readers with an option to customize our workflows.
Now, in the spirit of Getting Things Done, what if everytime iPhoto opens we actually import the photos? I know that sounds crazy but…
And, yes, I’m on a 1.33GHz PB, so my system’s usually crawling on the floor long before I connect my shattered iPhone…
Cheer up, haters!
Mark
on 22 Feb 08BTW, y’all might wanna check out Merlin Mann’s “Inbox Zero” presentation at Google.
ecobore
on 22 Feb 08Yep, I have to agree, Apple have slipped up here. I use Aperture for my pro stuff and iPhoto for the non-pro and I would like to allocate which app opens with which camera. C’mon apple, you are usually so good with this stuff…..!
Jennifer
on 22 Feb 08That seems like a lot of work on the programming side for something that should be just a click in the preferences menu.
For all the nice design and innovative architecture, mac sometimes has these quirks that just don’t make sense.
Alin Steglinski
on 22 Feb 08this is nuts… i dont feel like messing with code!
could someone just compile this into a ready made app that we just have to run and then trash?
oh, and APPLE… LISTEN UP HERE…
GET THIS INTO THE STANDARD FEATURES SO WE DONT HAVE TO MAKE LAME HAXIES!!!
steve Burchell
on 22 Feb 08Doesn’t work for me ?? With a sony cybershot running 10.4.11 on a G5 iMac. When I paste the second terminal script no device name appears either in terminal or on clipboard. One stupid question….after pasting in terminal do you have to (I don’t normally use terminal).
If it did work its a brilliant idea and will save me answering ‘decide later’ to the iphoto Q ‘do you want to launch etc’ everytime I plug in the camera.
KB
on 22 Feb 08FANTASTIC !!!
I’ve been complaining about this since I got my iPhone and now I don’t have to!
THANKS SAM !!!!!!!!
steve Burchell
on 22 Feb 08That should read “do you have to press ‘return’” ?
Ken
on 22 Feb 08Interesting script, but wouldn’t it be easier just to disable iPhoto opening when any camera is connected, and then just click on iPhoto in your Dock when you actually want to download pictures from a camera? This whole script is saving you one lousy click!
iPhone Checkbox Fairy
on 22 Feb 08Um… this is not unlike reaching over your shoulder to scratch your ass. Funny thing is, there is a magical checkbox.
Turn off photo sync for the iPhone.
No AppleScripts involved.
jurgen
on 23 Feb 08when i paste in the terminal commands, i get this…
usage: ioreg [-b] [-c class | -l | -n name] [-p plane] [-s] [-w width] [-x] where options are: -b show object name in bold -c list properties of objects with the given class -l list properties of all objects -n list properties of objects with the given name -p traverse registry over the given plane (IOService is default) -s show object state (eg. busy state, retain count) -w clip output to the given line width (0 is unlimited) -x print numeric property values in hexadecimalmanofwy
on 26 Feb 08Thank you – sanity has been restored. At least until Apple puts the checkbox in place that they ‘forgot’ the first time around, and the next, and the next…
Jemima Garthwaite
on 27 Feb 08What if I have more than one camera? Or if i sometimes plug in different memory cards, which each have different names by default, into different memory card readers?
How do I work with this code for multiple devices?
Benjamin Ragheb
on 27 Feb 08I wrote another version of the script, assuming that ioreg is listing devices in the order connected. If we assume the last device is the most recently connected one, we can check that it isn’t an iPhone and launch iPhoto, without having to find your camera’s name or worrying about edge cases like plugging in your iPhone when your camera is already connected.
details here
This discussion is closed.