Help with Duplicating files via Folder Actions

I have an Applescript set up to automatically print PDFs added to my Distiller “Out” folder, and want to add functionality where they will be duplicated to “waiting for OK” folders which change weekly, and I want to overwrite exisitng files.

I am trying to duplicate to alias folders so I can just change where the alias points to each week for the new folders.

Here’s the code I have so far, which generates an error after the printing:


property dialog_timeout : 120 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	repeat with this_item in added_items
		tell application "Finder"
			if file type of (info for this_item) is "PDF " then
				print this_item
			end if
		end tell
	end repeat
	
	set the alert_message to "Move them there files you just printed to a 'Waiting for OK' folder."
	set destination_path_ADS to "OS 9:Desktop Folder:ADS ¢ Waiting For OK  CURRENT:"
	set destination_path_CLASS to "OS 9:Desktop Folder:CLASS ¢ Waiting For OK  CURRENT:"
	
	display dialog the alert_message buttons {"ADS", "CLASSADS", "Nope"} default button 3 with icon 1 giving up after dialog_timeout
	if button returned of result is "ADS" then
		duplicate file this_item to alias destination_path_ADS with replacing
	else if button returned of result is "CLASSADS" then
		duplicate file this_item to alias destination_path_CLASS with replacing
	else
		display dialog "As you wish."
	end if
	
end adding folder items to

Any ideas what I am doing wrong?

Hi. You need to ‘tell application “Finder”’ to carry out the ‘duplicate’ lines.

Nigel,

Thanks, I totally overlooked that. Big time noob here, sorry.

But, I couldn’t seem to find a place where the tell worked, I still got the -120 error no matter where I placed it. Here’s what I thought it should look like:


property dialog_timeout : 120 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	repeat with this_item in added_items
		tell application "Finder"
			if file type of (info for this_item) is "PDF " then
				print this_item
			end if
		end tell
	end repeat
	
	set the alert_message to "Move the files you just printed to a 'Waiting for OK' folder."
	set destination_path_ADS to "OS 9:Desktop Folder:ADS ¢ Waiting For OK CURRENT:"
	set destination_path_CLASS to "OS 9:Desktop Folder:CLASS ¢ Waiting For OK CURRENT:"
	
	display dialog the alert_message buttons {"ADS", "CLASSADS", "Nope"} default button 3 with icon 1 giving up after dialog_timeout
	tell application "Finder"
		if button returned of result is "ADS" then
			
			duplicate file this_item to alias destination_path_ADS with replacing
		else if button returned of result is "CLASSADS" then
			
			duplicate file this_item to alias destination_path_CLASS with replacing
		else
			display dialog "As you wish."
		end if
	end tell
end adding folder items to


Hi again. With my own files and folders, the second version of your script does work for me in both OS 9.2.2 and in OS 10.4.5. Error number -120 is an operating system error that’s thrown when a folder can’t be found. Are the paths to the folders on your desktop correct? Do the folders exist? Are all instances of ‘this_item’ files, and not folders? (Use ‘item’ rather than ‘file’ in the ‘duplicate’ lines if you’re expecting a mixture.) Are you correctly expecting the duplicates to be created inside the specified folders? Just a few shots in the dark.

Interesting. I will have to look into this further on Monday when I am back at the shop.

I do believe that everything is correct - all files to be duplicated are files and not folders, and the duplicates should be created inside the folders; the folders on my desktop are aliases to this week’s current ad folders, the originals are on the network.

The only thing I can think of, not being in front of the work computer right now, is that the the aliases to which the script point are actually pointing to a set of aliases on my desktop instead of directly to the folders on the network drive where I actually need the files to be duplicated; not sure if that would affect anything.

I will have to triple check everything first thing Monday, thanks for testing things out and the very helpful feedback.

George