Loop Won't Stop

I have some code that keeps clicking a button while the screen contains an image. However, even after the image disappears, it keeps trying to click the button. But the button is no longer visible on the webpage in Chrome. So then I am stuck in this infinite loop. Any idea what is going on here? And how do I manually escape this loop?

image

Are you running this macro with the KM Editor open and showing this macro?

If you are, because the While is set to detect the image "in all screens" it is probably seeing the image in your macro and continuing to trigger because of that. The solution is to close the KM Editor app - there's no need for it to be running to run a macro anyway.

Instead of using "in all screens" you can specify a specific screen, a specific window, or a specific area on the screen. That would help if you want to keep KM Editor open.

I tried it when I had the task collapsed"

image

Also, it goes to a different part of the webpage to try to do the click. So, could it be that the web designers just hide the button image, but for some reason it is still visible to Keyboard Maestro?

Sorry - I forgot to say: click on the KM system menubar icon and click Cancel - you'll be able to kill running macros from there.

It gets difficult because while it is running, it is moving the mouse, so when I go to click cancel, the mouse has already moved back to the other page to click the invisible button!

If it's not visible on the screen, KM will not be able to see it.

Can you point us to the webpage URL?

Sorry - bombarding you with messages.

I've reread your original post: what is the actual problem you're trying to solve? Is it:

  1. The repeated clicking on the image while it is onscreen, or
  2. The seeming continued clicking when the image is not onscreen.

The problem is #2. url: https://tinder.com/app/matches

1 Like

I don't have a tinder account so I'm not going to be able to explore any further I'm afraid.

Maybe some other clever KM soul can help out :grinning:

I'm wondering if it is a case of the webpage hiding the button to the user but it still exists on the page, just with opacity set to 100% or something. I'm not sure how the KM image finder works.

KM looks at the screen pixels and tests them against the image swatch you've given it AFAICT. So if you can't see the image on the screen neither can KM.

To test - just check the Display checkbox in the action - it will result in the image that KM finds being highlighted for you to easily see.

What else is going on in your macro?

It seems strange that while the tick image is shown, it clicks each time in the location, but when it is not visible, it moves the mouse to a completely different location and (probably) ticks there.

Is it still within the bounds of the Chrome window?

Create a new, separate macro that looks like this (choose any hotkey you prefer)

KM 0 2021-05-10_16-04-13

When you trigger it, it will stop any running macros.

It is still within the Chrome window.

I've ticked the Display checkbox and get this:

image

Not sure what the 1% refers to, but that image is now pulsing every second. And, it doesn't appear to be clicked anymore.

It seems inconsistent. It started clicking now. But has stopped again.

Question: When you have the Editor open and click Run, does the macro just continue until it stops? What happens if you click Run, then choose another Macro and click that too? Do you then have two running simultaneously. Also, there seems to be no stop button for the macros, so you can break out, which I find a bit odd.

Yes - why wouldn't it? When you run Chrome on your Mac it continues until you stop it, no?

Yes. Your Mac can run any number of apps at the same time - so can KM with macros. However, it is usual to run macros using some kind of trigger - a hotkey for example (as I showed with my "kill" macro above) and NOT have the KM editor open all the time.

It is usual to design macros so that they do not loop forever. But if you create a "rogue" macro that does loop forever then you can use the techniques I gave you earlier to kill it. Equally, you can design macros to run until you press a key too. Most macros that people create however have a beginning a middle and an end so they start, do something(s) and then end. In case you're wondering, the "end" could be that there are no more actions in the macro to be executed, so KM just stops running the macro as there's nothing else for it to do.

Hope that helps.

Which Display checkbox did you click - you have 2 in the screenshot you posted originally?

I tried all combinations on the checkboxes.

When I run Chrome on the Mac, it runs until I close it. I see a tab in Chrome as analogues to a macro in KM. I can just click x to close the tab, but not so in KM to stop the macro.

My macro would be fine if it ended when the button disappears, but for some reason, it continues. Odd.

Perhaps it is some type of glitch that disappears when I get around to rebooting my computer. You never know!