I have an Applescript that runs all the time processing files as they come in. It uses Applescript’s built-in progress dialog for UI.
Occasionally - generally at random intervals fairly far between - it crashes. I’ve pretty well given up on figuring out why it crashes. Sometimes it runs for months.
It’s easy to find heuristics to figure out if it’s not doing its job, so I just wrote another app to watch it and restart it if it’s crashed.
The problem with this is that when it’s crashed, it generally won’t quit nicely, so I force quit it. But following a force quit, if I launch it by applescript using
tell application "AppName" to activate
it launches crashed. That is, it shows it’s running in the Dock and its application process name shows up in System Events, but its UI doesn’t come up and it doesn’t do anything. Usually the line:
tell application "System Events" to application process processName
Returns the process, but when it launches crashed, that line times out.
If I double-click it in Finder or click on it in the Dock after force-quitting it, when it launches, MacOS pops up a dialog saying:
With buttons “Don’t Reopen” and “Reopen.”
If I click the “Reopen” button, then it launches crashed. If I click “Don’t Reopen,” it launches fine and opens a new UI window and runs great.
So it seems that when I launch it with
tell application "AppName" to activate
It’s never showing that dialog asking about reopening windows, and is presumably defaulting to trying to reopen the window, which just crashes the program right away. Probably something about the progress dialog is what’s crashing the script in the first place?
Anyway, does anyone know a way around this? Is there anything I can add to the Applescript as a preference to never try to reopen windows after a crash? Is there some different scripted way to open it that would tell MacOS not to try to reopen the window?
Or maybe I need to find a way to open it where it does show the dialog, and I need to use UI scripting to detect the dialog and actually click the “Close” button?
Unfortunately, it’s hard to test with, because I can’t trigger the crashes… if it didn’t crash and get force quit, then it opens fine with a simple “activate.” Even if I force quit it, if it wasn’t crashed when it was force quit, it opens fine with an “activate.”
And usually when it really did crash, I don’t have time to mess around with experimenting with it… we need it running again ASAP.
edit: clarify what’s a MacOS window, and make contents of that window exact.