I am still working on the iPhoto spotlight comments script and I have hit another snag.
I have (with the help of kai) gotten the basic script to work and now I am trying to ask
“Finder” to get every photograph of a chosen folder regardless of if the image is in a
subfolder of the chosen folder. I am trying the entire contents search, but access is not allowed.
Can ya’ll help?
to getFiles from this_folder
tell application "Finder"
set these_files to a reference to (this_folder's entire contents whose name does not start with ¬
"." and comment is "" and (file type is "TIFF" or file type is "JPEG" or name extension is ¬
"tiff" or name extension is "tif" or name extension is "jpeg" or name extension is "jpg"))
try
these_files as alias list
on error number -1700
these_files as alias as list
end try
end tell
end getFiles
on commentEntered for this_file
tell application "Preview"
activate
open this_file
set {button returned:buttonReturned, text returned:textReturned} to display dialog ¬
"Add your comment:" default answer "" buttons {"Quit", "OK"} default button "OK"
end tell
if buttonReturned is "Quit" then
tell application "Preview" to quit
error number -128
end if
tell application "System Events" to keystroke "w" using command down
textReturned
end commentEntered
set this_folder to choose folder with prompt "Choose a folder containing images requiring comments:"
repeat with this_file in (getFiles from this_folder)
tell application "Finder" to set comment of this_file to my (commentEntered for this_file)
end repeat
Here is the completed script for anybody to use. It adds comments to photo’s so you can find photo’s like google images in your own library.
to getFiles from this_folder -- this paragraph gets the images within a folder
tell application "Finder"
set these_files to (files of (entire contents of this_folder) whose name does not start with ¬
"." and comment is "" and (file type is "TIFF" or file type is "JPEG" or name extension is ¬
"tiff" or name extension is "tif" or name extension is "jpeg" or name extension is "jpg")) --this will get all the photo's from any selected folder
try
these_files as alias list
on error number -1700
these_files as alias as list
end try
end tell
end getFiles
on commentEntered for this_file -- this paragraph opens the image in preview so you can see it while commenting
tell application "Preview"
activate
open this_file
set {button returned:buttonReturned, text returned:textReturned} to display dialog ¬
"Add your comment:" default answer "" buttons {"Quit", "OK"} default button "OK" --this allows you to comment on the photo
end tell
if buttonReturned is "Quit" then -- this allows you to quit anytime and save comments already entered
tell application "Preview" to quit
error number -128
end if
tell application "System Events" to keystroke "w" using command down
textReturned
end commentEntered
set this_folder to choose folder with prompt "Choose a folder containing images requiring comments:" --this selects the folder to look into for images
repeat with this_file in (getFiles from this_folder) --this adds the comment to the spotlight comments in get info
set the the_real_comment to (commentEntered for this_file)
set Characters_Returned to every character of the_real_comment
if the (count of Characters_Returned) is not greater than 5 then --this makes sure a real comment was entered
display dialog "no comment was entered"
else
set date_prompt to " : Comment entered on " -- this adds the date the comment was entered with the comment
set the_date to ((the current date) as text)
set a to {the_real_comment & date_prompt & the_date} as list
tell application "Finder" to set comment of this_file to my {a}
end if
end repeat
tell application "Preview"
quit
end tell