File Size Checker Issue

I am trying write a script that runs when a PostScript file is generated by a DTP app (Quark or InDesign) into a watched folder.

The issue is that, if the PS file is large, the folder action will initiate the script before the PS file has completely generated and unless the Finder is asked to update the watched folder, it shows the same file size regardless of the interval.

Also because of the Finder updating issue, the user can be fooled into prematurely initiating the script manually if they see a .ps file in their Finder window even though generation has not yet finished.

Another issue, perhaps compounding all of this, is that the users work from a server partition to the HD and there can be server slow-downs at various times through the day.

Unless someone has a better idea for a workaround, what I would like to do is have the script reference the PS file size at different time intervals and then compare the intervals and, if the file sizes are different, repeat until they are the same size with a timeout.

Here’s an example of one of the scripts I’ve come up with so far. I don’t think the syntax is entirely correct.

Any help would be greatly appreciated.

tell application "Finder"
	set Counter to 0
	repeat
		delay 2
		repeat 5 times
			update (get items of folder psFolder)
		end repeat
		set XpsFiles to ((items of folder psFolder) whose name extension is ("ps" as list))
		set XselectionList to {(XpsFiles as list)}
		set XselectedCount to count items in XselectionList
		set XpsFile to ((first item of folder psFolder) whose name extension is ("ps"))
		get physical size of XpsFile
		delay 2
		repeat 5 times
			update (get items of folder psFolder)
		end repeat
		set YpsFiles to ((items of folder psFolder) whose name extension is ("ps" as list))
		set YselectionList to {(YpsFiles as list)}
		set YselectedCount to count items in YselectionList
		set YpsFile to ((first item of psFolder) whose name extension is ("ps"))
		get physical size of YpsFile
		if physical size of XpsFile is not equal to physical size of YpsFile then
			with timeout of 120 seconds
				repeat until (physical size of XpsFile is equal to physical size of YpsFile) is false
				end repeat
			end timeout
			if physical size of XpsFile is equal to physical size of YpsFile then
				set Counter to Counter + 1
				if Counter is 2 then
				end if
			end if
		end if
	end repeat
end tell

Hi,

Maybe this thread helps.

That did the trick!!!
Simple, powerful and elegant. Wonderful solution.
Many thanks to iPhotoStuff, Adam Bell and you!!! :smiley: