How do i make this into a folder action???

We PDF about 500 pages a day (about 3 to 5 people PDFing at once) going thru a FullPress Spooler but right now all the PDFs are being dumped into one folder that we currently have to sort thru manually and then have to make to seperate folders so we can batch print the ones that we only need at the moment.
I found this script on the forums here that works great for the purpose of sorting pdfs by their name into folders, but i need to make this a folder action instead of a script that you execute when ever. Also if at all possible, i need to make it so when they are sorted into the folders they print automatically to a specified printer using the page size setup as the default in acrobat.

Can anyone please help me out??

Thanks!!

Below is the script that works for me so far


set the source_folder to choose folder with prompt "Folder containing items to edit:"
display dialog "What is the separator?" default answer "_"
set pp to POSIX path of source_folder

tell application "Finder"
	set filelist to every item of source_folder whose kind is not "Folder"
	repeat with i from 1 to number of items in filelist
		set nom to name of (item i of filelist)
		set bn to my textToList(nom, "_")
		try
			do shell script "mkdir \"" & pp & (item 1 of bn) & "\""
		on error
			--it is there already
		end try
		do shell script "mv \"" & (pp & nom) & "\" \"" & pp & (item 1 of bn) & "/" & nom & "\""
	end repeat
end tell
display dialog "Done"

on textToList(theText, theSep)
	set soFar to {}
	set textSoFar to theText
	repeat until theSep is not in textSoFar
		set thePos to the offset of theSep in textSoFar
		set thenewPos to thePos
		if thenewPos is 1 then set thenewPos to 2
		set nextBit to text 1 through (thenewPos - 1) of textSoFar
		if textSoFar is not theSep then
			set textSoFar to text (thePos + (count of text items in theSep)) through -1 of textSoFar
			copy nextBit to the end of soFar
		else
			set textSoFar to ""
		end if
	end repeat
	copy textSoFar to the end of soFar
	return soFar
end textToList

Model: 500 MHz PowerPC G4
AppleScript: 1.9.3
Browser: Safari 312.3.3
Operating System: Mac OS X (10.3.9)

Basically you wrap it in an ‘On Adding’ block:

on adding folder items to this_folder after receiving added_items
-- your script goes here
End adding folder items to  

The variable ‘this_folder’ is the name of the folder on which the action script is running and ‘added_items’ is a list of items added to ‘this_folder’ that caused the script to be triggered.

wish i could say it worked but nothing happens, no errors but it is not making the folders and moving the files when i tried to set it up as a folder action.
I have made sure that folder actions is enabled and this is the only one set for the folder
below is how i have it set now, what am i doing wrong?



on adding folder items to this_folder after receiving added_items
	
	set pp to POSIX path of this_folder
	
	
	tell application "Finder"
		set filelist to every item of this_folder whose kind is not "Folder"
		repeat with i from 1 to number of items in filelist
			set nom to name of (item i of filelist)
			set bn to my textToList(nom, "_")
			try
				do shell script "mkdir \"" & pp & (item 1 of bn) & "\""
			on error
				--it is there already
			end try
			do shell script "mv \"" & (pp & nom) & "\" \"" & pp & (item 1 of bn) & "/" & nom & "\""
		end repeat
	end tell
	display dialog "Done"
end adding folder items to
on textToList(theText, theSep)
	set soFar to {}
	set textSoFar to theText
	repeat until theSep is not in textSoFar
		set thePos to the offset of theSep in textSoFar
		set thenewPos to thePos
		if thenewPos is 1 then set thenewPos to 2
		set nextBit to text 1 through (thenewPos - 1) of textSoFar
		if textSoFar is not theSep then
			set textSoFar to text (thePos + (count of text items in theSep)) through -1 of textSoFar
			copy nextBit to the end of soFar
		else
			set textSoFar to ""
		end if
	end repeat
	copy textSoFar to the end of soFar
	return soFar
end textToList


hgeisler,

I believe that what you need to do is set the line

to

repeat with a in added_items
if kind of a is not "Folder" then
set filelist's end to a
end if
end repeat 

Give that a shot.

PreTech

Unfortunately, once you set up a folder action, any error in the script causes it to halt with no indication that anything was wrong. One thing I was never able to get to work for me was subroutines. All I could get it to tell me was that an error occurred. I’d suggest you comment out only the ‘on addin’ and corresponding ‘end’, ‘set’ a variable to the folder name manually, place a file in the folder then run the script manually. If there are any error mesages that will at least get them to show up. One other thing to check is that the script is in the right place (boot drive:Library:Scripts:Folder Action Scripts) and that it was saved as a ‘scp’ file. Saving it as an application or bundle would never work for me either. Good luck.

Well i managed to get it to work as a folder action after commenting out the display dialog. thanks for all your help!!
Now i just need to figure out how to make it print the files before it moves them. That might be hard/impossible. Any suggestions on getting that to work.

below is the final version that works as a folder action.



on adding folder items to this_folder after receiving added_items
	
	set pp to POSIX path of this_folder
	
	
	tell application "Finder"
		set filelist to every item of this_folder whose kind is not "Folder"
		repeat with i from 1 to number of items in filelist
			set nom to name of (item i of filelist)
			set bn to my textToList(nom, "_")
			try
				do shell script "mkdir \"" & pp & (item 1 of bn) & "\""
			on error
				--it is there already
			end try
			do shell script "mv \"" & (pp & nom) & "\" \"" & pp & (item 1 of bn) & "/" & nom & "\""
		end repeat
	end tell
	(*
	display dialog "Done"
*)
end adding folder items to
on textToList(theText, theSep)
	set soFar to {}
	set textSoFar to theText
	repeat until theSep is not in textSoFar
		set thePos to the offset of theSep in textSoFar
		set thenewPos to thePos
		if thenewPos is 1 then set thenewPos to 2
		set nextBit to text 1 through (thenewPos - 1) of textSoFar
		if textSoFar is not theSep then
			set textSoFar to text (thePos + (count of text items in theSep)) through -1 of textSoFar
			copy nextBit to the end of soFar
		else
			set textSoFar to ""
		end if
	end repeat
	copy textSoFar to the end of soFar
	return soFar
end textToList


:D:D