Help with Folder Action that auto compress files on my desktop

Thanks for any help I can get:
I’m have a folder on my desktop that I auto transfer files to…and I use (Control click create Archive) to make a .zip of all the files in that folder
so I can burn them to CD…Is there a way to automatically (Control click create Archive) all of the files that transfer to that folder so I don’t have
to sit and manualy do this for hours…

I tried to set up a folder action using information from these threads:

http://bbs.applescript.net/viewtopic.php?id=16754
http://bbs.applescript.net/viewtopic.php?pid=56566#p56566
http://bbs.applescript.net/viewtopic.php?id=16558

but I get an endless loop - zips of the zip that was just created. I figured out that I could throw the folder in the trash and secure delete it to stop the loop. I tried to fix it by checking for the .zip extension before running the shell script, but kept getting errors.

Could somebody please point me in the right direction? Thanks in advance.


--DON"T RUN THIS -  it keeps going.
on adding folder items to FilestoZip after receiving droppedFiles
	repeat with aFiletoZip in droppedFiles
		
		tell application "Finder"
			
			set theItem to aFiletoZip as alias
			set itemPath to quoted form of POSIX path of theItem
			set fileName to name of theItem
			set theFolder to POSIX path of (container of theItem as alias)
			set zipFile to quoted form of (theFolder & fileName & ".zip")
			do shell script "zip -r -j " & zipFile & " " & itemPath
			
		end tell
	end repeat
	
end adding folder items to

I tried this but still got the loop.

do shell script "zip -r -j -n .zip " & zipFile & " " & itemPath

Either I’m typing it incorrectly or barking up the wrong tree.

Thanks for the help capitalj:
I believe I have the zip folder action working…another problem has come up…I transfer these .job files through a network to a folder on my desktop
which has this folder action assigned to it…It seems to work but the .job file folder consist of multiple sub files .mlw and .nct files and sometimes not
all the files transfer to the folder action folder…The folder compresses but not all the files are in that folder so the zip file is of no use to me…
I process about 40 or 50 of these files a day…Is there a way to make sure all the information in that folder is transfered from the network to my desktop
so I can zip a .job that has everything including sub folders in that file. Oh yes (I mount my network drive onto my desktop and transfer from a folder on
the network drive to the folder action…
again thanks for the help…

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
set the destination_folder to folder “Done” of ¬
this_folder as alias
set the destination_directory to POSIX path of ¬
the destination_folder
end tell
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
if this_item is not the destination_folder and the ¬
name extension of the item_info is not in ¬
{“.zip”} then
set the item_path to the quoted form of the ¬
POSIX path of this_item
set the destination_path to the quoted form of ¬
(destination_directory & (name of the ¬
item_info) & “.zip”)
do shell script ¬
("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
item_path & " " & destination_path)
end if
end repeat
end adding folder items to

Sorry capitalj I forgot to post the script the correct way:

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
		set the destination_folder to folder "Done" of ¬
			this_folder as alias
		set the destination_directory to POSIX path of ¬
			the destination_folder
	end tell
	repeat with i from 1 to number of items in these_items
		set this_item to item i of these_items
		set the item_info to info for this_item
		if this_item is not the destination_folder and the ¬
			name extension of the item_info is not in ¬
			{".zip"} then
			set the item_path to the quoted form of the ¬
				POSIX path of this_item
			set the destination_path to the quoted form of ¬
				(destination_directory & (name of the ¬
					item_info) & ".zip")
			do shell script ¬
				("/usr/bin/ditto -c -k -rsrc --keepParent " & ¬
					item_path & " " & destination_path)
		end if
	end repeat
end adding folder items to

I’m not sure I understand your new problem (I am over my head and barely treading water to begin with.) I used your folder action, dropped a folder containing a file and a subfolder with its own file, and everything ended up in the zip file. Are you saying you want the subfiles to zip individually, outside of their folders?

Even if I understand your question, I don’t know if I can help. I’m still studying your script, and trying to make my shorter script work properly - learning by doing (well, almost doing.) If I figure something out, I’ll post back.

Don’t hold your breath.

j

No Capitalj if I manually drop files into the folder action it works fine now…But It seems to be my transfer script…from the network drive to the folder action
It does’nt seem to transfer all the information (Sometimes) to the folder action…I’ll post the script shortly…
Thanks for the help…

Maybe I’ll be able to do more than stare blankly at it.

I don’t seem to be providing more than moral support, but I do what I can.

I know you guys seem to have covered the zip part of the script using shell scripts.
but for your interest here’s how i zip folders full of files’ i’m sure one of you applescript savvy dudes
could convert it to your needs.

tell application "Finder"
	activate
	set x to choose folder --pick the folder to work on
	set theitem to every file of folder x
	repeat with theitem in theitem -- go through each item in the folder
		select theitem
		---------------------------------------------------------------------------------------------------
		tell application "System Events"
			tell process "Finder" to click menu item 21 of menu "File" of menu bar 1
			display dialog "Archiving.. Please Wait." giving up after 1
		end tell
		---------------------------------------------------------------------------------------------------
		-- this bit above creates the archive
	end repeat
end tell
tell application "Finder" to move (every file in the folder x whose name does not end with ".zip") to the trash
--this bit deletes the files that are left other than ones with extension .zip

Hey pidge1

I’m more noobie than savvy, which is why my folder action doesn’t work right yet.

Thanks for the example, the more I see the more I learn. I’m hoping this line from your script

tell application "Finder" to move (every file in the folder x whose name does not end with ".zip") to the trash

wil help me figure out how to prevent my endless loop by preventing newly zipped files from triggering the folder action (preferably without moving them, but I may need to concede defeat on that.) I think I’m dancing all around the solution.

If I can’t sort it out, Zeek’s script does almost exactly what I want. I’m continuing with my attempts partly because I’m stubborn.

j

Thanks for coming to the rescue, Jacques.

I had gotten as far as realizing I needed to work with lists somehow, but I was at a loss.

This was my first attempt at a folder action, and I noticed something that seemed strange. After dropping a file into the folder, the frontmost window does, for the lack of a better term, a bit of a blinky thing - like it drops back from frontmost for a fraction of a second once or twice. What is that?

I guess I should look these scripts over and make sure I understand them.

Thanks again,

j

Thanks, good to know.

I thought it must be normal, but wanted to be sure I hadn’t done something wrong since my poorly written script caused my desktop to flash like a strobe.

Although Jacques already solved my problem, I managed to make my version work, too, so now I can relax (as long as I don’t think about the fact that zips and originals are in the same folder - but I can fix that when I can’t ignore it anymore.)


on adding folder items to FilestoZip after receiving droppedFiles
	
	repeat with aFiletoZip in droppedFiles
		
		tell application "Finder"
			
			set theItem to aFiletoZip as alias
			set itemPath to quoted form of POSIX path of theItem
			set fileName to name of theItem
			if fileName does not end with "zip" then--this line fixed the problem
				set theFolder to POSIX path of (container of theItem as alias)
				set zipFile to quoted form of (theFolder & fileName & ".zip")
				do shell script "zip -r -j " & zipFile & " " & itemPath
				
			end if
			
		end tell
		
	end repeat
	
end adding folder items to