 |
 |
Help with scripted folders...
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2004
Location: MA
Status:
Offline
|
|
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:
Code:
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...
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
Since your code doesn't look that bad can you be more specific on how it fails? Did you activate Folder Actions? And did you put the script in an appropriate Folder Action Scripts folder?
-
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2004
Location: MA
Status:
Offline
|
|
Yes, the script went into the Folders Actions Scripts and I did attach it to the specific folder. I drop the images onto the folder and nothing will happen. No errors, no resizing, nothing. 
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Jan 2004
Location: MA
Status:
Offline
|
|
Figured it out!
I'm happy!
Code:
property type_list : {"TIFF", "JPEG", "PNGf", "PICT"}
property extension_list : {"tif", "tiff", "jpg", "jpeg", "png", "pict", "pct", "gif"}
tell application "Finder"
activate
try
set the source_folder to choose folder with prompt "Pick a folder containing the images to process:"
set these_files to every file of the source_folder whose file type is in the type_list or name extension is in the extension_list
repeat with i from 1 to the count of these_files
set this_path to (item i of these_files) as string
tell application "Image Events"
set this_image to open file this_path
-- IMAGE PROCESSING STATEMENTS GO HERE
scale this_image to size 550
-- save the changes
save this_image
close this_image
end tell
end repeat
on error error_message
display dialog error_message buttons {"OK"} default button 1
end try
end tell
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
Okay, on second sight you might just want to get rid of some typos:
Code:
on adding folder items to folder after receiving the_added_files
display dialog "" & "hello" & the_added_files
tell application "Image Events"
launch
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
end try
end repeat
end tell
end adding folder items to
Also remember to use display dialog to show yourself some diagnostic messages while debugging.
-
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2001
Status:
Offline
|
|
Ah, beat me by two minutes.
-
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|