twtwtw wrote:
Oooo, good point. It would probably be ok since it's reusing the same openedFile variable (that should automatically release the last image data), but to be on the safe side ludwip could replace the save line with the following:
closesavingyes
that would definitely avoid any such problems. He might even want to add the following lines to the on error section:
try
closeopenedFilesavingno
end try
which will try to close any opened image in the event of an error.
Thanks twtwtw,
Just to stay on the safe side.
Does the code supposed to look like this?
Thanks a lot for your input.
set folderToProcess to choose folder with prompt "Choose a folder to process"
set folderPath to quoted form of POSIX path of folderToProcess
-- 13 is a spotlight constant for images that I can't find documented anywhere (I got it by saving a spotlight image search in the Finder and examining it in a text editor). FYI.
set fileList to paragraphs of (do shell script "mdfind -onlyin " & folderPath & " '_kMDItemGroupId == 13'")
tell application "Image Events"
-- tell image event not to quit itself
set quit delay to 0
repeat with thisImageFile in fileList
try
-- open the image file
set openedFile to openthisImageFile
tell openedFile
-- you didn't specify which way or how much you wanted to rotate. this rotates them 90° clockwise
rotateto angle 90
-- save back to same file
closesavingyes
end tell
on error errstr
-- image events had an error - dislpay alert, then skip this file
my displayError(thisImageFile, errstr)
try
closeopenedFilesavingno
end try
end try
end repeat
-- reset Image Event's automatic quitting
set quit delay to 900
end tell
on displayError(thisImageFile, errstr)
tell application "System Events"
display alert "Image Events Error" message "file : " & thisImageFile & return & return & "error: " & errstr
end tell
set imageAlias to POSIX filethisImageFile
tell application "Finder"
set label index of item imageAlias to 1
end tell
end displayError