Rename - wait until file is accessible, or handle errors?

If I have a file open and try to rename it it throws error 32 (Process cannot access the file because....).
Is there a way for me to handle that error and have it wait for it to be accessible?
Like if:error is X or something?

This is for simple rename by the way, thought it would be nice for advanced rename to wait for multiple files.

Opus already waits half a second and tries again if a file cannot be renamed because it is in-use.

A longer wait could be done using a script which does the renames itself and retries based on the error code. If you know what is causing the files to be in use, a script may also be able to wait for it to finish before doing the rename.

Yea, generally it is because I have it open. So I use information from the open file in the name, then save the file and click retry to rename (since I know it is closed).

Would a script be able to wait for the specific document to close? I know how to use .net word interop but I don't know VBScript, is that possible?

If it waited automatically (longer than it already does), how would you know what was happening and that you needed to close a file, or which file to close?

I guess you want it to say what it is waiting for as well as waiting?

A script could do that but it makes things more complicated, and probably would not work well if you want this as a replacement for your general, built-in Rename functionality (not just for a specific rename operation within a larger operation/batch/script).

I was thinking more like a button in the error dialog or rename dialog that is like "wait till file is free" or something. I'd probably have it time out after 5 minutes though, with a notification or something.

It's really only for pdfs or docs, but yea I wouldn't want it to do it all the time.
I know I probably can't edit the built in error dialog, but would a script be able to catch an error thrown by the rename function and then retry every x seconds until x minutes pass?

It's really only needed for the one use case I do, so I would probably restrict it to certain folders and file types.

Scripts can't modify how the built-in error/retry dialogs work; the script would have to be the thing driving things.

Okay, I'll try and figure out VBS and see if it is feasible. I'll reply if I come up with anything.

Opus "chokes" itself trying to rename file for which thumbnails are still being generated. Not necessary, but would be nice if, in this case, Opus tried again without prompting the user to retry.