well, there are a couple of possibilities here:
- system events is quitting (it will do that on its own after a few minutes of inactivity) and he script is getting confused when it has to restart
- the file 00353391301.JPG is not a valid image file (corrupt data, or an unsupported file format with the wrong extension, or the wrong type of file entirely, or something like that).
so, covering the bases, try this revision:
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
save
end tell
on error errstr
-- image events had an error - dislpay alert, then skip this file
my displayError(thisImageFile, errstr)
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
tellapplication "Finder"
set label index of item imageAlias to 1
end tell
end displayError
This makes three changes - it tells Image Events not to quit itself during script execution, it expands the error handling block to cover all the Image Events functions (this will report more detail and not interrupt further processing), and as a convenience labels any problematic file orange in the finder so it's easier to find.
Also, I should point out that adayzdone and ludwip are presenting orthogonal approaches (one that finds files using the unix 'find' utility rather than mdfind, and one that's entirely unix-based using the underlying sips utility). Treat each approach as its own thing; don't get confused and try to implement parts of each of them. People on this forum sometimes forget how confusing help can be when helpers are working off of different models and fail to thoroughly contextualize their posts.