Trapping screen condition infinite loops post Yosemite

Wondering why KM has been hogging CPU post Yosemite, I launched the KM Debugger for the first time.

It immediately revealed a pause until screen contains ... condition tied to a pre-Yosemite version of an icon.

  1. I salute the excellent debugger (the issue wouldn't have come to mind for a long time)
  2. Short of a forced quit through Activity Monitor, what's the best way to stop a macro that has gone into an infinite loop ?


(PS clicking the X button in the debugger did clear it there, but the process continued to run and take up the same level of CPU capacity, so I quit it in the end with Activity Monitor)

The best thing to do is in the Macro, use the action timeout feature. If you click on the Pause Until step, look at the bottom of your Keyboard Maestro Editor window. You can set a timeout value. See image below.

. . . Stephen

1 Like

Good thought - thanks

Wow. Thanks Stephen. I can’t believe I didn’t know that one.

There is no need to force quit the Keyboard Maestro Engine for this. Cancel the macros (in the debugger or via the status menu Cancel submenu).

I’m not sure why that would be, but I expect it would return to a low CPU usage after a short period to time - Keyboard Maestro Engine will need to cancel the various screen searches which might not happen immediately even though the macro has been canceled, and Activity Monitor has a tendency to average out usage so that even after it stops it still shows as high usage for a while.

It doesn’t seem very obvious to me. Even when its turned on there is no easy way to see the timeout. Perhaps it would be better if KM showed it inside the action itself (at least when its enabled)?

Yes, the UI for timeouts is less than ideal. It is very hard to get a balance between more noise for every action and visibility/discoverability. I will be looking at options for 7.0 for improving the editor in this regard.

Cool, thanks. Is there anyway to limit the CPU usage - may add a pause or something into the polling? When searching for images the KM engine is taking a whopping 310% of my CPU on a 2015 MacBook Pro Retina (2.6 GHz Intel Core i7 with 4 cores).

One other tip for others is that the KM editor seems to run the image scan if you have any “find image” actions in the current macro. I assume so it can show if its “Currently true” or “currently false”.

Searching for images is a very CPU intensive job. When Keyboard Maestro is doing it, it uses all available CPU on all available cores in order to get good responsiveness.

The only way to limit CPU usage is to ask the question less often. So, for example, instead of Pause Until Image is Found, use While Image is not Found, Pause N seconds.

Yes, you are correct, the Keyboard Maestro editor, in order to show the “currently false/true” and other results, continually runs any action conditions/evaluations that are needed to display those results, and if that includes image searching, then it will have a significant impact on your CPU/battery usage while you leave them displayed.