Select iPhoto photos by file names


I’ve got a iPhoto Library with a few hundreds photos. They all have unique file names.
I also have a array of filenames, like “1.jpg, 6.jpg, 20.jpg”.

I want to make a selection of these photos on iPhoto and tag each photo with a keyword “snowboard” for example.
Adding a keyword is easy, however, getting Applescript to make a selection is not.

Any idea how I could achieve that?

Goal is, to have different photos tagged with different keywords.
These are however stored inside a SQL database.
I plan to execute a AppleScript inside PHP/Ruby that goes along like this:
Select photos 1.jpg, 6.jpg, 20.jpg and add keyword “snowboard”
Select photos 1.jpg, 45.jpg, 64.jpg and add keyword “rail”

I’ve never scripted iPhoto, but I’ve written a lot of scripts for Aperture and I guess they’re probably pretty similar.

In Aperture, unique file names won’t cut it. You need an array/list of image references. The way to build this is to loop through the library and add individual images to a list if they match your file name criteria. Then loop through this new list and tell each image to add a keyword.