Searching for a Trigger to Continuously Scan Screen for Image and Execute Action upon Detection. Any Suggestions?

Doesn't sound like I figured it out then. Let me think some more. Maybe you should upload your macro so I can deal with it rather than think about it.

I see one odd thing. You are not using the location of the mouse as I recommended when I said earlier, "mouse click action on ImageLocation.x, ImageLocation.y"

Another odd thing is that you are inserting a 20 hundred second pause. It's uneeded because of my 0.33 second pause. No need to double the time.

Certainly. Here it is:

Search for a Tree on the Screen every 0.33 seconds [custom edit].kmmacros (18.0 KB)

While i look at it, consider my two oddities that I put into my last comment.

For me, your macro results in a 0.5 second delay between each click. That means my 0.33 second pause and the 0.17 time it takes to run the check are adding up correctly.

But you are getting a two second pause? Either the time it takes for your Mac to run the check is about 1.5 seconds, or your loop is constantly seeing the image (never returning false). One way to test if this is possible is add a Beep sound whenever it DOES NOT find the image. This is to debug. If you never hear the sound, something may be wrong with the image you are using. That would be a clue.

In other words, add this near the bottom of your macro in the ELSE clause:

The reason I know my Mac was running your test in 0.17 seconds was that I added the following statement inside the loop:

... and when I looked at the Log variable I noticed about 0.5 seconds between each check. So the macro is working correctly on my Mac.

Got it! I added that in. I'm hearing the "pop" sound about every four seconds now continuously after the action is performed.

What do you make of this?

That means that the macro is failing to find the image some of the time. That's good. Unfortunately it means that the problem isn't failing to find the image. Perhaps you should do what I did, add that "Log" statement inside your loop and then look at the timestamps of each check. That might give us a big clue.

You can remove the Pop statement for now. Run my Log without any Popping sound.

My approach is sound, and your actual macro even works fine on my Mac. So something else is at play. What kind of Mac do you have, an Intel Mac from 20 years ago?

Got it, just added it. I see the string of numbers below the action and they update by a value of ~1 every 1 second (due to the 1 sec periodic trigger?)

I am running a Late 2013 Mac Pro. 64 GB RAM.

Then I think what's happening is your macro is failing and restarting. That's good news(!), because it means we have a good lead. Let me think about that for a minute.

Okay, for testing purpose I want you to delete the semaphore action (or just disable it) and then delete the periodic trigger (or just disable it). Then run the macro manually, by pressing the Run button. Hopefully that speeds it up. Keep the Log action in there for now. But you can delete the Log variable first so that your old data is deleted.

If it still takes two seconds per check, then maybe the problem is the 10 year old video card in that Mac.

I'm eager to hear your results. I want to know what possible mistake I could be making.

Your theory that this was "due to the 1 sec periodic trigger?" is possible but not likely because all the "Notify on error flags" in your macro were enabled, and you didn't get any notifications, right? Nonetheless it would be wise to check the Engine log file to see if there is an error occurring every second. It's possible.

Thanks - I did this, unfortunately the speed remains as was.

Correct, no error notifications received.

So if the loop is taking 1 second per iteration even after disabling the trigger, then that means the Find Image action is actually taking 1.0 seconds to execute on your 2013 Mac Pro. I just can't think of any other explanation. Let me create another test to give us a clean approach. I'll post it here in a minute or two.

Okay run this little macro. It does 100 Find Images and then reports the average time per run. On my Mac it's 0.28 seconds. Tell me what yours says.

Group Action (v11.0.1)

Group.kmactions (146 KB)

Keyboard Maestro Export

Sorry I'm going to need a little more guidance on this one -- when I attempt to add this to KM, I get a message that says "Import from URL must be editing a macro".

What macro is this to be created in? What trigger, if any?

Where should I be looking for this?

I've never seen that error before. Let me google it. Oh I think i see what happened. You imported my "action" because I uploaded it as na action not as a macro. Hang on.

This should work better BUT I want you to be aware that when you imported my action two minutes ago, it was added to whatever macro you already had open!!!! Better check.

Speed Test Macro (v11.0.1)

Speed Test.kmmacros (204 KB)

This will import my macro as a macro. You can run it by pressing the Run button when you open it.

Screenshot 2023-12-14 at 12.11.02 AM

Well, there's your problem. Your Mac takes nearly one second to search for an image on the screen. Now we know everything.

Maybe I should add this code to my OCR Speed Test macro so users can collect another data point on their Mac's speed.

You won't be able to use Find Image more than about once per second. Not on that Mac. Even though it's bad news, at least we diagnosed it.