MacOS – How to pause Applescript when another process is not responding to system events

applescriptmacosterminalunix

I would like a Applescript to pause while a specific process/script/app is not responding (temporarily or permanently) to system events, and to start-up again when the other process is back. In theory this could be done with a repeat loop provided there is a way to monitor the status of the process. Is there any code that can do this? via Terminal commands? via Applescript? Another possibility: can Applescript determine when the cursor has switched to the beach ball? Other ideas?

Quite simply in applescript terms, this is what I'd like:

repeat while "beach ball is spinning"
end repeat

Best Answer

This may be convoluted but try using try and with timeout to probe for lack of response to an appleEvent. The target app will have to have at least the standard suite dictionary.

try
    with timeout of y seconds
        ## request something simple like set x to name for testing
    end timeout
on error
    ## whatever needs to happen during a stall
end try