Is there a way for a script to determine if a file is open (not busy) without using lsof in a shell script? I have searched the forum and found some handy lsof shells that pointed me in that direction. It works, but watching Activity Monitor, the lsof process spikes up to 97% of the CPU every time it runs! That is even when I am searching only a single directory. I know that the “info for file” command reports back busy status, but open files are not busy files.
Here is the lsof script I am running now, maybe something could be done to make it less processor intensive.
set source_folder to (alias "TheVolume:ThePath:TheFile:")
set var to false
repeat until var = true
try
set the_files to (do shell script "lsof -F n +D " & (quoted form of POSIX path of source_folder))
on error the_error
if the_error = "The command exited with a non-zero status." then
set var to true
display dialog "The Document is closed"
else
set the_files to the_error
end if
end try
delay 1
end repeat
Thanks for the reply. You are correct, I didn’t need the +D. That’s what I get since I don’t know what I’m are doing and I copy stuff off other posts. The folder I was checking with lsof is only one level deep anyway. It still used 97% of the CPU even when I took out the +R, so back to the drawing board.