How can I tell if a file is busy?

If you want to incorporate a check in your script to determine if a file is busy, you can check the busy status property using the info for command, from Standard Additions, born in AppleScript 1.4, OS 9.

busy status of (info for alias "MacHD:some file.txt")

Some times, “busy status” will return “false”, when it should be “true” (under some special circumstances). You can try then:

try
	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

For previous versions of operative systems, use the fileIsBusy command from Jon’s Commands. The scripting addition returns true if the file is currently open and false if the file is not currently open. For example,

fileIsBusy alias "MacHD:some file.txt"

This returns false if not running, true if it is.

If you are still sure the file is opened, and none of these methods seems to return a “true” value, you can use the *nix tool “lsof”, which will return a list of all busy files in the system.