Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript to find a photo by name, add comments - iPhoto

Applescript to find a photo by name, add comments - iPhoto
Thread Tools
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Jan 29, 2005, 02:58 AM
 
Hi,

I'm trying to write an applescript that will add comments to a photo in iPhoto. I have descriptions and associated filenames for about 200 photos and I want to drop them into the photos' comments field. The pix are already in iPhoto and sorted in to albums, etc.

All the examples I can find for iPhoto deal with an image that is already selected but I need to go the other way. I want to find and select an image based on filename or title.

Can this be done? I can't seem to stumble onto the right syntax. Apple's
iPhoto scripting page specifically mentions 'searching' for a photo.


I've tried variations on this, no go :

set this_comment to 'some comment'
tell application "iPhoto"
activate

set this_photo to select (photo whose title is "DCP_6392.JPG") -- this is what it chokes on

tell this_photo
set the comment to this_comment
end tell
end tell

I've even tried having two more beers and it still isn't working.

I could probably do a shell script that drops the comments into the IPTC tags. then use the example script to move the IPTC tag data into the iPhoto comments. But that's more of a hassle.

thanks
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jan 29, 2005, 06:09 AM
 
AppleScript is a bit more layered than that - The photos belong not to the application object, but to albums of the application object:

[php]
tell application "iPhoto"
set allAlbums to every album


repeat with i from 1 to number of items in allAlbums
set thisAlbum to item i of allAlbums
tell thisAlbum
-- get properties
set photosList to (every photo whose name is "IMG_0185.JPG")

try
tell first item of photosList
set comment to "Rah, Rah, Rasputin: lover of the Russian Queen."
end tell
end try

end tell
end repeat

end tell
[/php]
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jan 29, 2005, 07:13 AM
 
oh, by the way - the code above will add the comment to *any* file with the given name - so if you have several photos with the same filename (as i did - different people's cameras) they will all have the new comment applied.
     
Gavin  (op)
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Jan 30, 2005, 12:23 AM
 
Thanks, that does the trick!

I AM going to run into the 'same name' issue. This is for a friend and his camera's filename odometer has wrapped already. Most of the descriptions are for the early pix so I'll drop it out of the loop when it finds a match.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:07 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2