Detecting if a file is done copying?

I am trying to find a script that will detect if a file is done copying.

The specific situation is a large file (~500MB) coming across a network into a watched folder. The folder action is supposed to activate once the file is done copying. Even though the first line of the folder action is:

on adding folder items to my_folder after receiving the_files

AFTER RECEIVING… the script still starts before the files are done.

I tried both of these methods for detecting if a file is “busy”:

busy status of (info for alias "MacHD:some file.txt")
   open for access file x
   --> file is not busy (ie, it's not locked and you can write data to it)
   close access result
on error
   --> file is busy
end try

From here:

They both always return true, making them useless. Any ideas?


I found this Handler somewhere (not tested):

on isFileBusy(thePath)
	--Tests to see if a file is in use
		set myscript to "if ( lsof -Fp " & thePath & " | grep -q p[0-9]* ) then echo 'file is busy'; else echo 'not busy';fi"
		set myResult to do shell script myscript
		if myResult is "not busy" then
			return true
			return false
		end if
	on error err
		return false
		--display dialog ("Error: isFileBusy " & err) giving up after 5
	end try
end isFileBusy

Greets from

on delayUntilFileSizeStopsChanging(theFile)
	set timeDelay to 15 -- the time to wait between size checks in seconds
		set sizeThen to size of (info for file (theFile as text)) --get initial size
			delay timeDelay
			set sizeNow to size of (info for file theFile) -- get new size
			if sizeNow - sizeThen is less than or equal to 0 then exit repeat
			set sizeThen to sizeNow
		end repeat
	on error
		return false
	end try
	return true
end delayUntilFileSizeStopsChanging