in Code

Mass add keywords to iPhoto with Launchbar

I was playing with iPhoto this morning and decided that, really, it would be better to properly tag my photos and use smart collections, rather than have them in unwieldy folders which clutter up the left sidebar, and which I can’t delete without losing the associated classifications. (If I don’t keep a folder called “Cats” current, I’ll never be able to find all pictures of cats again, unless the next version of iPhoto includes an automatic cat recognition routine, which actually isn’t all that bizarre an idea, but anyway.)

The first thing I discovered was that I couldn’t see any way to add tags – or rather, keywords, as iPhoto calls them – en masse, which seemed very odd. (It may have a mechanism which I didn’t find.) But that’s what we have Applescript for isn’t it?

Edit: after writing this post I was informed that Cmd-K brings up a list of tags in iPhoto, which can be used to mass tag photos. However, I shall keep this blog post here because (a) the Launchbar integration means it can easily be done via the keyboard and (b) the script itself might be useful for people as a starting point for keyword manipulation in iPhoto.

So I started writing a script to do this. The second thing that I noticed was that, in some cases, keywords just were not being added to pictures, and I found that iPhoto silently refuses to add keywords via Applescript which don’t actually exist in its list of keywords. A bit annoying, but surely, easy to overcome – after all, we can get a list of all keywords in iPhoto, so just check that first, and if the keyword doesn’t exist, add it before trying to tag the photos. Surely.

The third thing that I learnt this morning was that it seems to be entirely impossible to add new keywords to iPhoto via Applescript. You just can’t do it – you can’t make a new keyword at all, it kicks up errors when you try, including the ever helpful “AppleEvent failed”.

So the result is a script which does mass add keywords, but only keywords which already exist. It warns you if they don’t rather than just failing; you’ll have to add them to one photo manually first. But I have now replaced my manual folders with smart folders and events, and my sidebar looks a lot tidier. I also now find it a lot quicker to tag photos using the keyboard only, via Launchbar.

Here’s the script to download:

You can run the script itself to tag the selected pictures and specify the keyword via a dialog box, or you can run the script using Launchbar and specify the keyword within Launchbar, by the usual method of finding the script, pressing space, typing the keyword and pressing return.