# Selecting nonRAW photos in iPhoto via AppleScript

I’ve started using the RAW format on my Canon G10 and have run into a small annoyance when importing into iPhoto. Both the RAW image and an accompanying JPEG of the same photo are imported, giving me two images for every photo.

The JPEGs seem unnecessary; they contain less information than the RAWs and new JPEGs can always be generated from the RAWs. Selecting the JPEGs and deleting them is easy when I’m importing only a few images, but it’s tedious when importing dozens. Here’s a semi-automated to do it.

1. Have the Event you’ve just imported showing in iPhoto, as in the screenshot.
2. Run the “Select non-RAWs” script described below (I use FastScripts, but there are other ways).
3. Deselect any JPEGs that don’t have an associated RAW, because we don’t want to delete those.
4. Delete the selection.

Here’s the AppleScript that does the selecting:

1:  tell application "iPhoto"
2:    set rawKW to item 1 of (every keyword whose name is "Raw")
3:
4:    select (every photo in current album whose keywords does not contain rawKW)
5:
6:  end tell


The script takes advantage of the fact that iPhoto automatically gives every RAW image the “Raw” tag. As usual, a seemingly simple AppleScript actually involved much trial and error to make sure the distinctions between strings, lists, and the ever-mysterious “references” are honored. Also note the “English-like” construction in Line 4:

whose keywords does not contain


Lovely.

The script would be much better if I had been able to write it like this:

tell application "iPhoto"
set rawKW to item 1 of (every keyword whose name is "Raw")
set rawNames to name of every photo in current album whose keywords contains rawKW
select (every photo in current album whose keywords does not contain rawKW and name is in rawNames)

end tell


This would select only those JPEGs that have a corresponding RAW, and Step 3 of the procedure wouldn’t be needed. Unfortunately, trying to run this script leads to an error:

iPhoto got an error: Can’t make {"IMG_1050", …} into type reference.


This is, apparently, a known problem for which I couldn’t find a straightforward workaround. If you know of one, email or Twitter me.

Update (7/10/09) After reading this post at maccreate.com, I went looking for a setting to prevent my camera from automatically creating a JPEG along with the RAW. This morning I finally found it. Not making or importing the JPEG in the first place is a much better solution than what I’ve described in this post.