Folder Action script doesn't wait for files to finish

I have a Folder Action script that converts uncompressed tiffs into LZW tiffs making use of the tiffutil command. This script works as long as you move tiff files into the hot folder. If you copy the file to the hot folder the Folder Action script WILL NOT WAIT for the copy to complete before acting. The resulting files become corrupt. I tried waiting for the file status to become unbusy and that did not work, as the file was not considered busy even while it was incomplete. In this next attempt I tried to look for evidence of the file size not changing as evidence that the copy was complete. When I do this the script does not work at all. It’s as if there was some major syntax error in the script and so nothing happens.

To duplicate results take a 40 mB tiff image and copy it into a hot folder that uses the below Folder Action script and see what happens. Can someone help me?

Below is the script:
on adding folder items to this_folder after receiving dropped_items
set item_count to number of items in dropped_items
display dialog (item_count as string) & " items were added"
repeat with i from 1 to item_count
set the_dropped_file_path to item i of dropped_items
set item_info to info for the_dropped_file_path
repeat while busy status of item_info
delay 0.7
end repeat
set filechanging to true
set oldfilesize to (size of (info for the_dropped_file_path))
display dialog (oldfilesize as string)
repeat while filechanging is equal to true
display dialog (“file changing”)
delay 1
set newfilesize to (size of (info for the_dropped_file_path))
display dialog (newfilesize as string)
if newfilesize is equal to filesize then
set filechanging to false
end if
end repeat
display dialog (“file done”)
set item_path to the quoted form of the POSIX path of the_dropped_file_path
if name extension of item_info is “tif” then

		--if busy status of (info for the_dropped_file_path) then
		--display dialog ("file is busy")
		--end if
		try
			--display dialog ("Item #" & i as string) & ": " & ((POSIX path of the_dropped_file_path) as string)
			do shell script ("tiffutil -lzw  " & item_path & " -out  " & item_path)
		on error
			display dialog "Error: File not compresed"
			return
		end try
	end if
end repeat
display dialog "compression done"

end adding folder items to:(:(:frowning:

I wrote a script that is a stay open application with an idle handler that gets around this problem.

see:

http://scriptbuilders.net/files/folderactionreplacement1.0.0.html

You will need to replace the code in the ProcessThisFile handler, and then save the script as a stay open application. To use the script, run it and it will ask you for the folder that you want it to watch. While it is running it will not process a file with the same file name twice, The script will show up in the Dock as a running application.

Do not try and attach this script as a folder action.

Kevin