Modifying a Remote File - NSCocoa Error

I have a macro that mounts an AFP share (another Mac on my network), then runs a search-and-replace on a specified file. Sometimes it works flawlessly, but other times I get an error notification. The error in the log reads:

Search and Replace action failed to set result with error Write File failed to write file to /Volumes/mymountedshare/Documents/myfile.sh with error Error Domain=NSCocoaErrorDomain Code=512 "“myfile.sh” couldn’t be removed." UserInfo={NSUserStringVariant=(
    Remove
), NSFilePath=/Volumes/mymountedshare/Documents/myfile.sh, NSUnderlyingError=0x600002834900 {Error Domain=NSPOSIXErrorDomain Code=16 "Resource busy"}}

I don't know what causes the (occasional) failure. "Resource busy" seems to be a clue, but the file in question is not being accessed locally so I don't know how it could be 'busy'. Any thoughts?

One possibility is that two instances of your macro are running concurrently. What is the trigger for your macro? If that's not the problem, I doubt I can solve it.

If you can sanitize your macro (removing sensitive information) without changing how it works, then posting it may help you get an answer.

I run it manually (from a palette) so it's unlikely that there are two instances running. I'm wondering if the issue has to do with file permissions (since the macro works on a file from a remote volume). Obviously outside the scope of KM if so!

Maybe there's another process, like an intermittent backup application, somewhere on the network that grabs the file from time to time.

Do you have multiple users on different Macs sharing the same macro?

Did you consider opening the Debugger to make sure there was only one macro running?

I'm doing my best to come up with ideas, but I'm running dry. At least you read the log file, which is something I often forget to do.

Yes! There IS another process that calls the same .sh file that my macro is doing - thanks for putting me on the right track.

I added some steps to tell the remote Mac to stop that process before the file is manipulated by my macro (and further steps to restart the process afterward). Hopefully this will remedy the error - time will tell!

Some days I solve nobody's problems. Some days I solve 3 or 4. Thanks for making this one of my better days.