Wait to Open

This part of my script is opening a file after an ftp transfer, but
it’s trying to open it before it’s completely transferred. How can I
test for completion or somehow delay the open until the upload is
finished?

on adding folder items to this_folder after receiving added_items
tell application “Finder”
set the folder_name to the name of this_folder
end tell
repeat with anItem in added_items
tell application “Finder”
open anItem
end tell
end repeat
end adding folder items to

Thanks,
Chris

Here’s how I deal with similar situations.

on adding folder items to this_folder after receiving added_items
	
	tell application "Finder" to set the folder_name to the name of this_folder
	
	repeat with anItem in added_items
		
		-- Begin New Stuff --------------------------------------------
		-- Check to see if size of downloaded file has changed. Keep checking until file
		-- size stops changing. The sleep might need to be modified to deal with slow
		-- network conditions.
		
		set fileSize to 0
		set latestCheck to 1
		
		repeat until fileSize is equal to latestCheck
			set fileSize to size of (info for anItem)
			do shell script "sleep 2"
			set latestCheck to size of (info for anItem)
			if fileSize is equal to latestCheck then
			else
				do shell script "sleep 10"
			end if
		end repeat
		-- End New Stuff --------------------------------------------
		
		tell application "Finder" to open anItem
		
	end repeat
end adding folder items to

Rob:

t seems like your code only handles the problem if you have dropped multiple items into the folder simultaneously. What if the script is processing added items and another tiem gets added? In my case it messes up the processing of the first batch of files.

NOTE: Processing each file through Photoshop CS is a part of the process. So my guess is that if Photoshop is busy processing, that’s the cause of my problem.

Any suggestions?

I don’t know what happens, or what can be done to avoid problems, when items are added while other items are being processed. I suspect that control of this situation is in the hands of Apple’s developers but I can’t say with certainty.

– Rob