Simple macro with While action does not work + strange never seen behaviour - must quit KM engine to close engine window

Hello,

I managed to have 3 problems with a simple macro

1- the image does not display when Cleanshot is active and at the front

2- If I activate cleanshot and trigger the macro, the image is displayed but ... it cannot be closed. The only way to close the image is to quit the Keyboard Maestro engine.

3- I would liked to know how to toggle an image display (just for my education).

thanks very much for your patience !

Display while Cleanshot at the Front.kmmacros (203.0 KB)

Screenshot (click to expand/collapse)

I think I can tell what you are trying to do. But there's a funny bug in your macro due to a misunderstanding that you have.

You are creating an infinite number of windows because you are creating hundreds of windows in an infinite loop. You can close them all without closing the KM Engine, but you have to click hundreds of times.

I'm surprised that the KM Engine lets you create hundreds of windows. I would have expected it to fail at some point. Maybe I didn't wait long enough for it to fail.

So there are two things wrong with your macro. 1. You are creating hundreds of windows in a loop. 2. You are (in my opinion) using the wrong action to display a clipboard.

Here's the action that's intended for displaying an image:

image

Now as for cancelling the pop-up window, normally that's up to the user to close the window manually. I think there's a way to remove it programmatically, but I'll respond to that in a separate reply later, unless someone beats me to it.

1 Like

One way to "close" the window is described on this page, but you have to use the Custom HTML window to display the window, not the actions described in the posts above. It's a perfectly valid solution. There may be other solutions, which I am still looking for.

Here's another technique you can use and adapt to your situation:

The above macro will display a window then use a token inside another action to close the last created window. In your case, this should suffice, but it's probably better and safer to save the Window ID into a variable and then use that variable later to close the window.

1 Like

That's a easy/separate issue.

You can create a macro that activates when the application you want (Cleanshot) is activated, which will display the window, and then you can create a macro that activates when a different application is activated. (You could even combine them into one macro, but for now let's keep it simple for now.)

So you first macro would look like this: (replace "Keyboard Maestro" with "Cleanshot X")

And your second macro would look like this:

Just don't forget to include the "Set Next Engine Window Position and Size" actions like you already are doing before you display the window.

1 Like

Fantastic. All clear. Thanks very much for your detailed explanations. ! Infinite loop: yes! Now I understand.

Your idea of having a pop-up window whenever an app is frontmost is quite an interesting idea and I suspect others will copy your approach.

You will get the most flexibility in the window if you use the Custom HTML action.

1 Like