I'm not sure if anyone else mentioned this or not. You could have the macro use "Execute a JavaScript in a Custom HTML Prompt" to tell the prompt that the macro has set the variable.
So rather than have the prompt wait in a loop for the variable to be set, it would trigger the macro and not do anything else.
When the macro sets the variable, it can execute a Javascript function in your Custom HTML Prompt, like this:
And in your "variableHasBeenSet" function, you can read the variable's value, then do whatever you were going to do with it. It would be nice if you could actually pass the variable's value in this way, but I can't find a way to do it.
I hope this makes sense. If not, let me know.