Get applet to ignore 'on reopen' requests while a dialog box is open?

As the title says. Is this possible? Does anyone know how?

Long version:

What ends up happening is my users click on the applet icon in the Dock to bring it back to the front after doing something else.

While a dialog is active in the applet, that’s all fine. But since I have a reopen handler (which provides necessary functionality and isn’t removable), when they click on the applet icon 3 or 4 times when switching back and forth between all their apps (as one would in normal use), as soon as they’re done with the applet, the reopen handler runs that many times in a row, which confuses them (it would annoy me too).

I’m not at all confused about why it’s happening, but I’m absolutely confused at Apple’s reasoning here as to why AppleScript applets were designed like this.

Why can’t there at least be an option to block ‘on reopen’ clicks from adding to this virtual queue while the applet is doing something else? I’ve tried clunky solutions to do just this, but they don’t work. Any suggestions?

What is your on reopen handler doing, and can you share some of your attempts, no matter how clunky ?

I recall an issue like this a few years ago.

I believe I put a global in the script called lastFinishedTime

Then the open handler would have:

if theTimeNow - lastFinishTime < 120 then return

(I believe it was a stay open applet.)

I can possibly try, but I’m not sure how illuminating it would be. They’re across multiple scripts so I’ll have to dig it up. Lots of attempts too.

Interesting idea. How does this work in practice? I’m not quite wrapping my head around how time relates to the user triggering an unwanted reopen event while a dialog box is open.

I think my scenario was a little different, but basically if the number of seconds since the last time the handler was called was less than 120, then the handler wouldn’t continue. If it was more it would.

Ah, I see. Unfortunately this wouldn’t work for me in practice, I think.

I need the applet to ignore the calls to the reopen handler while the handler itself is running, but it should allow calls to the handler any time it’s not running/actively displaying a dialog. I hope there’s a solution! :slight_smile: