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 > Folder Actions help

Folder Actions help
Thread Tools
Grizzled Veteran
Join Date: Sep 2002
Status: Offline
Reply With Quote
Nov 5, 2003, 09:18 AM
 
I'm trying to write a folder action and I need a little help...

I have a directory for my web site called "originals" which contains PNG graphics, and I'd like to have a folder action that automagically compresses the files with the built-in Finder "Create Archive" command, and deletes the original PNG image.

Can anyone help? I'm clueless.
AIM: toast1911@mac.com
     
Senior User
Join Date: Oct 2000
Location: Midwest
Status: Offline
Reply With Quote
Nov 5, 2003, 09:45 AM
 
What event would trigger the compression? When new .png files are added? Is this a one time occurence? A bit more info will help.

Craig
     
Sal
Dedicated MacNNer
Join Date: Sep 2000
Location: Cupertino, CA USA
Status: Offline
Reply With Quote
Nov 5, 2003, 12:36 PM
 
Originally posted by fat mac moron:
I'm trying to write a folder action and I need a little help...

I have a directory for my web site called "originals" which contains PNG graphics, and I'd like to have a folder action that automagically compresses the files with the built-in Finder "Create Archive" command, and deletes the original PNG image.

Can anyone help? I'm clueless.
Start here:

http://www.apple.com/applescript/folderactions/

Your folder action script will most likely use the "do shell" command to archive items with the "compress" command or something similar.

BTW, the new Script Editor in Panther supports contextual menu scripts that can insert code snippets into a script for you automatically.

Click in a new script window with the control key down and select "Folder Actions Handlers > Adding to Folder" to insert the Folder Actions handler for the added items event.
     
Sal
Dedicated MacNNer
Join Date: Sep 2000
Location: Cupertino, CA USA
Status: Offline
Reply With Quote
Nov 5, 2003, 12:45 PM
 
Something like this. Note that you must move the added items to another folder to keep the folder action from being triggered again when the item is compressed.


Code:
on adding folder items to this_folder after receiving these_items tell application "Finder" if not (exists folder "Done" of this_folder) then make new folder at this_folder with properties {name:"Done"} end if repeat with i from 1 to number of items in these_items set this_item to item i of these_items set this_item to (move this_item to folder "Done" of this_folder with replacing) as alias set the POSIX_path to the quoted form of the POSIX path of this_item do shell script ("compress " & POSIX_path) delete this_item end repeat end tell end adding folder items to
     
   
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:41 AM.
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