Waiting for command completion in Finder

I have a folder action script that prints a file in a folder (drop box) and then deletes it. My problem (after much frustration trying to figure out what is wrong) is that the apparently the delete occurs before the the previous print completes. The script is:

on adding folder items to this_folder after receiving added_items
	
	set tiff_folder to this_folder
	tell application "Finder"
		repeat with file_name in folder tiff_folder
			print file_name as alias
			delete file_name as alias
		end repeat
	end tell
	
end adding folder items to

If I remove the delete command it works fine. When the delete command is in then the application is launched but by that time there is no file left to open. That tells me the delete command does not wait for the print command to complete. How do I make it wait? TIA.

I don’t think the file must actually have printed, but it does have to be entered on the print queue for your printer before you delete it. If the application that prints it is not actually open (whatever opens the tif file), then you have to wait for that first.

The Printer Setup Utility dictionary has (in the Print Center Suite) this:

so you could check there.
Sorry I haven’t had time to try this myself yet, but it’s where I would start.

Hi,

I’m using Jaguar, but think you still have Print Center in Tiger. You can script Print Center and find the status of the printer. Here’s an example on one file in a folder.

set f to choose folder
tell application “Finder”
set file_list to every file of f
set the_file to item 1 of file_list as alias
print the_file
delay 5
end tell
tell application “Print Center”
set p to current printer
end tell
repeat
beep 1 – for testing
tell application “Print Center”
set s to status of p
if s is (idle) then exit repeat
end tell
do shell script “sleep 2”
end repeat
tell application “Finder”
set do_quit to exists process “Print Center”
delete the_file
end tell
if do_quit then tell application “Print Center” to quit

Test it out and add error checking.

gl,

Perfect. :smiley: Works great. Thanks.