Hi, I just recently had a need to automate some redundant tasks. Notably, I need to resize jpegs and gifs and I figured using a scripted folder was the easiest solution.
I’ve searched the forums, tried the scripts on Apple’s web site (http://www.apple.com/applescript/imageevents/) and poked around in other places. I’m using Image Events because the images I’m resizing are sometimes 800+ pixels wide & others are 800+ pixels high, and the example on Apple’s web site using Image Events will resize by largest dimension (width or height).
This is what I came up with, and it fails miserably:
on adding folder items to folder after receiving the_added_files
tell application "Image Events"
launch
repeat with the_file in added_files
try
set this_image to open this_file
scale this_image to size 550
save this_image as JPG with icon
close this_image
end try
end repeat
end tell
end adding folder items to
I’d appreciate some input on this, having to use GraphicConverter to resize is becoming a chore…
Image Events is cool and you’re closer than you think.
First things first… folder actions are hard to debug, so forget that part for a second and look at the core…
I changed…
on adding folder items to folder after receiving the_added_files
tell application "Image Events"
launch
repeat with the_file in added_files
try
set this_image to open this_file
scale this_image to size 550
save this_image as JPG with icon
close this_image
end try
end repeat
end tell
end adding folder items to
To this…
set myfile to choose file
set the_added_files to myfile as list
tell application "Image Events"
repeat with the_file in the_added_files
try
set this_image to open the_file
scale this_image to size 550
save this_image as JPEG with icon
close this_image
on error error_message number error_number
return {error_message, error_number}
end try
end repeat
end tell
Don’t activate image events.
You have “added_files” in your repeat statement but meant “the_added_files”
You have “this_file” in your open but you meant “the_file”
Your save type should be “JPEG” not “JPG”
If you have a try wrapper, always include an on error so you can see what’s up.
Get this code working in script editor, then replace your on adding folder items stuff (which is correct as you wrote it) and you’ll be all set.