Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Help with scripted folders...

Help with scripted folders...
Thread Tools
Forum Regular
Join Date: Jan 2004
Location: MA
Status: Offline
Reply With Quote
Feb 28, 2004, 04:59 PM
 
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
Reply With Quote
Feb 28, 2004, 05:27 PM
 
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?

-
     
splatq  (op)
Forum Regular
Join Date: Jan 2004
Location: MA
Status: Offline
Reply With Quote
Feb 28, 2004, 05:58 PM
 
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.
     
splatq  (op)
Forum Regular
Join Date: Jan 2004
Location: MA
Status: Offline
Reply With Quote
Feb 28, 2004, 06:31 PM
 
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
Reply With Quote
Feb 28, 2004, 06:33 PM
 
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
Reply With Quote
Feb 28, 2004, 06:35 PM
 
Ah, beat me by two minutes.

-
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2