I’m attempting to create an app that will move files (some of them large) and I need to know when they aren’t busy. Simple enough, right? That’s what I thought.
Every time I check the ‘busy status’ of a file that is in the process of being copied, the result is always false. I’ve never seen a ‘busy status’ of true. Am I crazy or just stupid?
Right from the start the ‘info for’ reports that the ‘busy status’ is false and never changes. Perhaps I have something wrong. Any thoughts would be appreciated!
set TheResults to (info for file (FileToGetInfoOn))
if busy status of TheResults then
--wait and then check again
--do something now that busy status is false
The short version: you can’t use busy status under OS X, it apparently has a different meaning under Unix. The workaround is to try to open the file with write access; if you succeed, the file was not in use by another app, so you can close it and do what you want.
Bummer. It looks like I have to do it the hard way. Thanks for the help!
Here is a pre-writen one:
Checks if you can write to a file or not (if it is opened for access by other process).
f: file path, alias, posix path
isBusy("path:to:file.txt") --> false
set f to f as Unicode text
if f does not contain ":" then set f to POSIX file f as Unicode text
if busy status of (info for alias f) then return true
--> but some times this is not good enough
open for access file f with write permission
close access result