Remove duplicates when importing RAW images

Jul 07, '10 07:30:00AM

Contributed by: tempel

My camera can take RAW pictures, and can also store them in both a RAW and a JPEG format (i.e. RAW+). This is convenient when importing the pictures onto an iPad as the iPad doesn't need to decode the RAW pictures then on its own, which would be pretty slow.

When I later import these pictures from the iPad onto my Mac using iPhoto, I end up with duplicate items for each picture (the iPad groups them nicely together and shows only one item). This means that I see each picture twice in the iPhoto browser. I hope that Apple will eventually make iPhoto as smart as the Photos app on the iPad, by showing grouping the two formats for the same picture automatically. But until then, I like to tidy those dupes up myself.

I needed a way to seperate the RAW files from their JPEG twins. However, while iPhoto lets me search for items with a specific keyword (here: Raw), it seems to offer no way to find items not having a particular keyword, nor a way to invert a selection.

Automator offers the 'Filter iPhoto Photos' action, but that one seems to have a bug (as of July 2010) in which the is not operator for searching keywords doesn't work properly. So I wrote an AppleScript to sort it out.

How to find the non-RAW files in iPhoto

The script looks at all currently selected items in iPhoto and finds those that do not have the 'Raw' keyword. Those then get assigned the 'non-raw' keyword. With that 'non-raw' keyword, iPhoto lets me find these items easily so that I can, for instance, delete them, as I still have the RAW versions (I have to make sure, though, that I really do still have the RAW versions, as the script won't check that!).

Here's the AppleScript code. To use it, simply launch AppleScript Editor and paste the following code in, then save it as File Format: Application. To use it, first select the group of pictures from which you wish to identify the non-RAW images, and then run this script or application. You can then view the progress in iPhoto, where it adds the keywords to all non-Raw pictures you had selected.

  on run
   tell application "iPhoto"

    set selectedPictures to selection

    -- look at every selected picture
    repeat with img in selectedPictures

     -- check if the picture has a "Raw" keyword
     set isRaw to false
     set kws to keywords of img
     repeat with kw in kws
      if name of kw is equal to "Raw" then
       set isRaw to true
      end if
     end repeat

     -- add the "non-raw" keyword if the picture is not a raw picture
     if not isRaw then
      select img
      assign keyword string "non-raw"
     end if

    end repeat
   end tell
  end run
I'm sure the checking for 'Raw' keywords can be improved, as well as the script could collect all non-raw items first, finally set the selection and keyword only once. If you have improvement suggestions, please post them here or contact me through the link provided below.

(Note: I've also posted this on my own website.)

[crarko adds: I haven't tested this one, but did compile the script in AppleScript Editor successfully.]

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=2010070511411674