Folder Action - wait for files from FTP

I am using a mac with FTP file sharing in a local network to store music. Multiple users can connect and add music to an iTunes library. I have an automator folder action set up on the host computer that will automatically add the files to the iTunes library - it is a dropbox idea. It works great in testing from the desktop, but when transferring over FTP, the script runs before the files have transferred. Is there a way to trigger it after the transfer is complete??

Is there no way to access the final filesize to check against? The finder obviously knows it to make the progress bar.

I found the Folder Action isDone() script,
http://bbs.applescript.net/viewtopic.php?id=11476
which is what I’m looking for, but it doesn’t quite work.

I’m trying to make it call my automator script once it is done copying, but it usually fires early. Am I calling automator from the wrong place?


-- written by Jeff Case 2004
property LSreturn : ""
global CurrentFileSize, LastFileSize, StillBusy, StillGrowing
on adding folder items to this_folder after receiving added_items
	try
		-- get the name of the folder
		tell application "Finder"
			set the folder_name to the name of this_folder
			-- find out how many new items have been placed in the folder
			set the item_count to the number of items in the added_items
		end tell
		ProcessAddedItems(this_folder, added_items, item_count)
	end try
end adding folder items to

on ProcessAddedItems(this_folder, added_items, item_count)
	-- loop through the files looking for finished files to process
	repeat with x from item_count to 1 by -1
		set File2Check to (item x of added_items) as string
		set AppleScript's text item delimiters to ":"
		set TheFileName to text item -1 of File2Check
		set AppleScript's text item delimiters to ""
		set LastFileSize to -1
		set Ready2Rock to false
		beep
		
		--loop waiting for the file to finish writing
		repeat until Ready2Rock is true
			-- modify the path accordingly - point to isDone().scpt on your machine
			set testResults to run script alias "Macintosh HD:Users:fort:Library:Scripts:isDone().scpt" with parameters {File2Check, LastFileSize}
			set CurrentFileSize to item 2 of testResults
			if item 1 of testResults is true then
				set Ready2Rock to true
			else
				set LastFileSize to CurrentFileSize
			end if
			
			
			
			
			delay 1
		end repeat
		
		-- now that the file has finished writing,
		-- process the file while it's in this folder
		-- if the file is so big another move would
		-- require another isDone() check
		
		
		
		-- (YOU MAY OR MAY NOT WANT TO DO THE FOLLOWING, DEPENDING ON YOUR NEEDS)
		-- then move the file to a "done" folder
		-- so the folder action can pick up
		-- a new file with the same name
		-- because Folder Actions don't "see" overwrites
		-- only new files added are acted upon, not updates or overwrites
		-- tell application "Finder" to move alias (File2Check) to folder "path:to:done:folder:" -- intertpret as necessary
		
	end repeat
	
-- !! !!
-- !! This is what I added !!
	
tell application "Macintosh HD:Users:fort:Library:Workflows:Applications:Folder Actions:addFolders2iTunes2.app"
		open added_items
	end tell

-- !!
--	
end ProcessAddedItems

Ok, I think I was putting the automator call in the wrong place, it is now not in the subroutine but after the subroutine call. but the script is still not working consistently. I added a 10 minute pause before it tries the preloader. Still not 100% reliable though.


-- written by Jeff Case 2004
property LSreturn : ""
global CurrentFileSize, LastFileSize, StillBusy, StillGrowing
on adding folder items to this_folder after receiving added_items

delay 600	

try
		-- get the name of the folder
		tell application "Finder"
			set the folder_name to the name of this_folder
			-- find out how many new items have been placed in the folder
			set the item_count to the number of items in the added_items
		end tell
		ProcessAddedItems(this_folder, added_items, item_count)
	end try
	
	tell application "Macintosh HD:Users:fort:Library:Workflows:Applications:Folder Actions:2iTunes.app"
		open added_items
	end tell
	
end adding folder items to

on ProcessAddedItems(this_folder, added_items, item_count)
.