Need workaround: "Switch to application" doesn't work when KM input is on screen

I have a OneNote Search macro where I first type text into an input. Once that's submitted, I switch to OneNote where I do the search.

The problem is, if the macro is run multiple times (so multiple KM User Input dialogs are showing) then the process breaks. Submitting the input activates the next input dialog (which was hidden by the second input dialog) and OneNote is never activated.

Primarily I think this is a bug, because Application Switch should work in such a situation - the fact that KM has two user input dialogs up should not matter.

For now, is there some way I can work around this? E.g.:

  • Check + prevent two of these boxes from coming up
  • Somehow force KM to switch applications when it apparently doesn't want to
  • Close ALL identical prompt dialogs when one is closed/submitted

I believe part of the issue here is that the KM input dialog is not considered an input of KM (if I click that dialog now for example, my menu bar is still "Firefox" not KM). The dialog is also not part of the current application (can't cmd+` switch to it). So it's in a no-man's land I'm not familiar with.

I tried "bring window to front of front application" but this also doesn't work for some reason though logically it seems it should... somehow the KM dialog is pinned on top and nothing can wrench focus away.

That's all the ideas I have for now, any help?

Hey @Freewalker,

See Semaphore Lock on the Wiki.

Prevent a Macro from Running More Than Once at a Time v1.00.kmmacros (6.1 KB)

Switching apps works just fine for me with two user prompts open, but perhaps you're doing something different than I am.

You should post your macro, so we can debug your actual work rather than have to guess at what you're doing.

If you haven't read this it's worth a couple of minutes of your time.

How to Post Your Macro to the Forum

And this:

Tip: How Do I Get The Best Answer in the Shortest Time?

It's just a floating window that's attached to the background Keyboard Maestro Editor process.

The window floats on top of everything – that's what it's designed to do.

You can't hide the window, but you can wrest focus away from it to work within an app.


Thanks for the details and I've read over the materials you recommended. I'm sharing a minimal repro here.

KM version: 9.2

(This is a OneNote example but works the same with other apps, e.g. Messages.)

Repro steps:

  1. Press hotkey twice, opening two prompts
  2. Hit Enter to submit prompt

Result: Top prompt closes (bottom prompt still open) and OneNote activates

  1. Press hotkey twice again, opening two more prompts (3 are now open)

  2. Press enter

Result: OneNote is not activated; instead a KM prompt is activated.

This is one way to repro and repros 100% consistently for me. Any insight on that issue?

Regarding the Semaphore idea, I like it except that if I happen to have had this prompt open already I'd like to macro to still show a prompt - ideally focusing the existing prompt. I'm not sure how to do that though (focus an existing prompt). It would solve the issue of popping up too many boxes but would be a bit annoying if the box doesn't activate, though this would be a corner case for sure.

Test ON search.kmmacros (2.5 KB)