I know, how to import pictures into iPhoto with AS.
But, how can I import the Spotlight Comments into iPhoto? I want to add this comment into iPhoto comment. Is this possible?
tell app "iPhoto" to set comment of selection to "the comment text" as Unicode text
You have two options. First, create an empty album in iPhoto, and import the images into that album. You then select every image in that album, and use your script to set the comments. Then, you simply delete all the images from that album, and you are left with an empty album for your next import.
Second, purchase iPhoto Library Manager, which has extensive AppleScript capabilities and can perform all the importing, commenting, etc. that you need.
Good luck, please post again if you need more help.
set theFiles to choose file with prompt "select pictures to import" with multiple selections allowed
repeat with oneFile in theFiles
tell application "Finder" to set {theName, theComment, thedate} to {name, comment, creation date} of oneFile
tell application "iPhoto"
try
import from oneFile
if theComment is not "" then
set comment of (get 1st photo whose image filename is theName and date is thedate) to theComment
end if
end try
end tell
end repeat
Stefan, could your script be modified such that on import keywords would be added for each level of nested folders a photo resides in? For example if my photo has this path …images:travelling:California:2007:…could 3 keywords be added: Travelling, California and 2007?
Try this, you can change the maximum depth in the property.
property maxdepth : 3
set theFiles to choose file with prompt "select pictures to import" with multiple selections allowed
repeat with oneFile in theFiles
tell application "Finder" to set {theName, thedate} to {name, creation date} of oneFile
set {TID, text item delimiters} to {text item delimiters, ":"}
try
set theComment to text items -maxdepth thru -2 of (oneFile as text)
on error
set theComment to text items 1 thru -2 of (oneFile as text)
end try
set text item delimiters to ", "
set theComment to theComment as text
set text item delimiters to TID
tell application "iPhoto"
try
import from oneFile
if theComment is not "" then
set comment of (get 1st photo whose image filename is theName and date is thedate) to theComment
end if
end try
end tell
end repeat
Hi, again. Thanks for your help. I’m still stuck. The first part of the script works fine. I used a “display dialog” statement to see that the variable “TheComment” was correctly defined as the names of my folders. However, I want to assign the photo’s keyword to that value and that doesn’t seem to be happening. Should this conditional assign a keyword to be “TheComment”?
.
if theComment is not "" then
set comment of (get 1st photo whose image filename is theName and date is thedate) to theComment
end if
I figured out that comparing the dates doesn’t work reliably.
So try this, it works on my iPhoto 08
property maxdepth : 3
set theFiles to choose file with prompt "select pictures to import" with multiple selections allowed
repeat with oneFile in theFiles
tell application "Finder" to set {theName, thedate} to {name, creation date} of oneFile
set thedate to date string of thedate
set {TID, text item delimiters} to {text item delimiters, ":"}
try
set theComment to text items -maxdepth thru -2 of (oneFile as text)
on error
set theComment to text items 1 thru -2 of (oneFile as text)
end try
set text item delimiters to ", "
set theComment to theComment as text
set text item delimiters to TID
tell application "iPhoto"
try
import from oneFile
repeat while importing is true
delay 0.5
end repeat
if theComment is not "" then
set thePhoto to (1st photo of last rolls album whose image filename is theName)
if date string of (get date of thePhoto) is thedate then set comment of thePhoto to theComment
end if
end try
end tell
end repeat