Delay folder action, wait till all files have been copied to a folder

My problem i’ve decided to utilise a Dual 1.8Ghz PowerPC G5 mac running 10.5.4, this mac will be the centre for converting RGB TIFFs to CMYK EPSs and applying a profile mainly done by the Photoshop action (the TIFFs can be as little as 10mb and as large as 70mb) and saving them to a directory on a SGI running RedHat.

The files will be from some 6 to 8 other macs using airport (not the fastest way to transfer 2gb of photography) to transfer/copy to a shared folder on the G5 mac that has the script below attached as a folder action (thanks to a post i found on this site). The script works well and as you can see i’ve added two delays, the reason is files could still be in the process of being copied to the folder while Photoshop converts and saves, without the delays photoshop “catches up” with the copied files and tries to open a file still in the process of being copied and there the process ends.

Now the the crux of the problem, does applescript have a smarter way than the delay to wait till all files are copied ie “before opening each file check there is an EOF” or “the folder is still receiving file(s) i’ll wait till i’m no longer receiving file(s)”

I’d like to add that I am new to applescript and scripting in general and to this site but not to workflows as most of my work is done using Dalims Twist (hence the SGI running redhat), before the questions start Twist can do alot but it lacks the finesse of Photoshop to convert RGB to CMYK, Photoshop does a better job, the files are from a remote photographic studio using a 10mb link in to our network.

This is probably one of the longest posts for such a small script and I apologise beforehand.


on adding folder items to this_folder after receiving added_items
	delay 30
	set destinationFolder to ("Macintosh HD:Users:mymac:Desktop:test")
	repeat with oneItem in added_items
		try
			do_PS_action(oneItem, (destinationFolder & name of (info for oneItem)))
		end try
	end repeat
	tell application "Finder" to delete added_items
end adding folder items to

on do_PS_action(I, N)
	delay 30
	tell application "Adobe Photoshop CS3"
		do action "tiff to eps" from "convert.atn"
		save current document in file N
		close current document saving no
	end tell
end do_PS_action

Hi

Check out this previous post i think its on similar lines to what your asking.
http://bbs.macscripter.net/viewtopic.php?id=17912

Hope it helps.

Thanks for the link, here’s the final script (just in case somebody else can use it), works a treat but i think it will need adding/tweeking to at some point in the future.


on adding folder items to this_folder after receiving added_items
	if folderReady(this_folder) then
		set destinationFolder to ("Macintosh HD:Users:mymac:Desktop:test")
		repeat with oneItem in added_items
			try
				do_PS_action(oneItem, (destinationFolder & name of (info for oneItem)))
			end try
		end repeat
	end if
	tell application "Finder" to delete added_items
end adding folder items to

on folderReady(tFolder)
	set myFolder to tFolder as alias -- use the path to the folder that's loading
	set firstSize to size of (info for myFolder) --get initial size
	delay 5 --wait 5 seconds
	set newSize to size of (info for myFolder) --get a newer size, bigger
	repeat while newSize ≠ firstSize --if they don't equal, loop until they do
		set firstSize to newSize --new base size
		delay 3 --wait three seconds
		set newSize to size of (info for myFolder) --get a newer size
	end repeat --once the sizes match, the transfer is complete
	return true
end folderReady

on do_PS_action(I, N)
	tell application "Adobe Photoshop CS3"
		open I
		do action "tiff to eps" from "convert.atn"
		save current document in file N
		close current document saving no
	end tell
end do_PS_action