Hey everyone,
I’m using an Applescript to import photos into iPhoto, and I was having quite a bit of trouble trying to keep track of the ‘id’ of each photo after importing. Unlike iTunes, iPhoto doesn’t return a pointer to the object after importing, so I was stuck trying to find a workaround for grabbing the database of the id of the photo I just imported.
I couldn’t find a solution for this posted anywhere, so I came up with this hack. If anyone has any comments about the code here, and/or other suggestions to get this done, feel free to post em’! I figure that this is a pretty common thing to want to do, as it’s usually a good idea to keep track of all the stuff that you’ve already added to iPhoto, by storing the database IDs of each added photo somewhere outside of iPhoto…
-Clayton
set tempFile to (POSIX file (tempPath & "/" & fName)) as alias
tell application "iPhoto"
if (exists (album "000temp000")) then
set tempAlbum to album "000temp000"
remove tempAlbum
end if
new album name "000temp000"
set tempAlbum to album "000temp000"
import from tempFile to tempAlbum
delay 0.5
repeat while (importing)
delay 0.5 -- wait 1/2 second and try again
end repeat
set tempPhoto to first photo of tempAlbum
set cTrackID to (id of tempPhoto)
remove tempPhoto from tempAlbum
remove tempAlbum
end tell
Model: ppc G5 (10.5.8) & intel MBPro (10.6.2)
AppleScript: newest (as of 30 Jan 10)
Browser: Firefox 3.5.7
Operating System: Mac OS X (10.6)