Watch compressor output and sort when complete

Ok, here’s what I have going. I have a watch folder that opens any files it gets with 2 different compressor droplets. One creates a high-res clip, the other creates a low-res, deinterlaced clip. They output to two different folders. I have a script on the second folder that needs to do a few things.

A) wait for any incoming files to finish before starting. This means don’t do anything if there are still .mov-1 files in the folder.
B) move the outputed files to a server share, sorting them by number.
C) move the output files of the first folder to a local drive, also sorting by number.
D) delete the original file.

Now, I’ve gotten it to work sometimes, but it’s not reliable. If Compressor works quickly, it will only sort the last file outputted. Some times it will do steps A and B but then stop. What’s going wrong here?


on adding folder items to this_folder after receiving these_items

try
	mount volume "smb://user:pass@server/share/"
	delay 10
end try



repeat with this_item in (these_items)
	if name extension of (info for this_item) is "mov" then
		tell application "Finder"
			set file_name to (name of (info for this_item))
			set file_digits to (text 1 thru 5 of file_name)
			set lib_item to file (":RAID Storage 700:new captures:archiving:librarytemp:" & (file_name))
			
			if (file_digits is greater than or equal to 10000) and (file_digits is less than or equal to 13999) then
				
				set rel_digits to (text 1 thru 2 of (file_digits))
				
			else if ((file_digits is greater than or equal to 40000) and (file_digits is less than or equal to 49999)) or ((file_digits is greater than or equal to 90000) and (file_digits is less than or equal to 99999)) then
				
				set rel_digits to (text 1 of (file_digits)) & "0"
				
			end if
			
			duplicate this_item to folder (rel_digits & "000s") of folder "/share/"
			
			move lib_item to folder (text 1 thru 2 of (file_digits) & "000s") of folder "Commercial Library" of folder "RAID Storage 700"
			
			move file (":Raid storage 700:new captures:archiving:" & file_name) to trash
			
			move this_item to trash
			
			
			
		end tell
		
	end if
end repeat

end adding folder items to

Ok, now I think maybe I should just have the compressor droplet run the script on output. I can’t get this to work either though. Do I save the script as an application?

EDIT- The only way I can get it to work reliably is by saving it as an app and running it manually when I know there are no compressor jobs running. This will work, but if there is a smarter way to automate it let me know please.