Find out if Macro is being held by semaphore

I have two macros that work together, Prepare Data and Choose from Data.

Prepare Data runs periodically in the background. Choose from Data is triggered by a hotkey and displays a prompt that lets me interact with the data gathered by Prepare Data. Since they make use of the same variables, I keep them from running at the same time with a semaphore.

Sometimes I press the hotkey to trigger Choose from Data and the prompt doesn’t appear. I’m confused and press it again! Then I remember “Oh, it’s probably been blocked by the semaphore.”

I would like to set a notification to pop up in these circumstances to let me know “Sorry, the Prepare Data macro is running; your prompt will appear as soon as it’s finished.”

Is there a way to test whether the macro is being held by the semaphore?

In your Choose Data macro, do a Semaphore Lock, with a timeout of 1/hundredth of a second, and configured to not notify or abort.

Then if the action result is not OK, notify yourself and then repeat the Semaphore Lock without the timeout restriction.

Keyboard Maestro Actions.kmactions (1.9 KB)

Thanks! Great solution.