-- modify delays as needed set delayAfterOpeningPreferences to 0.25 set delayAfterSwitchingToKeywords to 0.25 set delayAfterTypingAKeyword to 0.35 set delayAfterReturn to 0.2 property error_log : null set thisKeyword to "no comment" -- keyword for errors property thisDay : ((year of the (current date) as string) & "/" & (month of the (current date) as number) as string) & "/" & (day of the (current date) as string) & "/" & (hours of (current date) as string) & "-" & (minutes of (current date) as string) -- day value for error log file set logAnswer to button returned of (display dialog "Do you want to create a log (at the desktop) or add \"" & thisKeyword & "\" keyword to the images which cannot be processed?" buttons {"Log", "\"" & thisKeyword & "\" keyword", "none"}) -- which kind of log do you want? set bErrorKeyword to false set bErrorLog to false if ("\"" & thisKeyword & "\" keyword") is equal to logAnswer as string then set bErrorKeyword to true --log "keyword log activated" my addKeywordsToIPhoto(thisKeyword) else if "log" is equal to logAnswer then set bErrorLog to true --log "error log activated" else --log "no error log" end if tell application "iPhoto" set selectedPhotos to selection -- run on selected photos in iPhoto if the class of the first item of selectedPhotos is not photo then display dialog "You should at least select one image in iPhoto." buttons {"OK"} default button 1 else repeat with thisPhoto in selectedPhotos set thisPath to image path of thisPhoto set thisPath to (POSIX file thisPath) as string try set bError to false tell application "GraphicConverter" set iptcInfo to get file iptc of thisPath set thisCaption to first item of iptcInfo end tell on error thisError -- could not get iptc info or no image selected --log "errorHandler" if bErrorLog then my writeLog(thisPath & return & thisError & return & "--------------") end if if bErrorKeyword then select thisPhoto assign keyword string thisKeyword end if set bError to true end try if not bError then set comment of thisPhoto to thisCaption end if end repeat end if end tell on writeLog(this_error) if error_log is null then set the error_log to ((path to desktop) as text) & "Script Error Log " & thisDay & ".txt" -- initialize error log file name end if try open for access file the error_log with write permission write (this_error & return) to file the error_log starting at eof close access file the error_log on error try close access file the error_log end try end try end writeLog on addKeywordsToIPhoto(thisKeyword) -- add keyword as defined above for errors tell application "iPhoto" set existingKeywords to name of every keyword end tell if existingKeywords does not contain thisKeyword then tell application "System Events" tell process "iPhoto" activate -- open preferences window keystroke "," using {command down} delay my delayAfterOpeningPreferences -- switch to keywords preference pane click button "Keywords" of tool bar 1 of window 1 delay my delayAfterSwitchingToKeywords -- add keyword tell window 1 tell group 1 click button "+" keystroke (thisKeyword) delay my delayAfterTypingAKeyword keystroke return delay my delayAfterReturn end tell end tell -- add keyword to list of existing keywords set existingKeywords to existingKeywords & thisKeyword -- hit escape to exit the properties window tell window 1 key code 53 end tell end tell end tell else return end if end addKeywordsToIPhoto