Is there a way to click on the image found in "Pause Until Found Image"?

just saw: toward the bottom, my "Click at (0,0) from the Center of the Found Image action should have said in “front window” rather than in “all screens.” Best to decrease how much Keyboard Maestro has to go searching for images as much as possible :slight_smile:

Hi Peter,

Still have to painfully manually write loops to pause for an image and then click it :stuck_out_tongue:

Could you perhaps store the image coordinates of an image found in Pause Until in %ActionResult% ?

This assumes %ActionResult%.midx, %ActionResult%.midy would work…

If not, perhaps could automatically store in a default variable such as %Variable%FoundImageCoordinates%?

ActionResult would not work well, firstly it needs to be “OK” for a successful image, and secondly there might be multiple conditions, even multiple Image conditions, so it doesn’t make sense for it to be used as a result.

It is possible there could be some other token that could contain the last found image location.

yes, Yes, YES! :slight_smile: :slight_smile: :slight_smile:

I’ve added a %FoundImage% token for the next version.


My hero!! :heart_eyes:

Hi. Is there a new way to do this (a loop that clicks on a found image) with KM 8 ?

It would be nice if solutions proposed on KM’s forum would be a little bit more detailed.

For example, when peternlewis writes:

Pause 0.1 seconds
Find Image on Screen
variable Location is not empty
Click at Location.MidX, Location.MidY

I don’t know where to set
Click at Location.MidX, Location.MidY
In an action ? In a script ?

Thank you.

As a general rule, my answers are very terse, because a) I don’t have a lot of time, and b) I believe people are better served by learning about the answer and figuring out the details themselves so they can apply them more constructively in the future.

You set Location.MidX and Location.MidY in the fields in the Click Mouse action. In the numeric fields, which expand to make room for variables once you start typing, as described in Text Fields.

Make sure the Click action is set to be relative “absolute”.

Hey Peri,

Your question is similarly lacking details. Please reframe it with more information about your process.

There are many examples of working with the found image on the forum, and then there’s the wiki.

Look for “found image” in the search on the wiki:


OK, OK. Thank you both of you.
(I thought KM was done for lazy people :smiley: Sometimes, I spend so many time to make a macro reliable that I wonder if the gain of time worth the effort. Its only because I am obstinate that I don’t give up. I like to learn by myself, I do it a lot since a couple of years but, you know, it is not often remunerative. )

Peter, I could have sworn that in a recent version you added a token that stores coordinates of found image if Pause Until image found succeeds? I can’t find it here or in wiki!

He did indeed. It’s called, appropriately enough, %FoundImage%. You can find the wiki page here:
And a prior thread showing it in action here: Drag Finder selection to “Found Image” in Chrome Browser window

1 Like

Thank you! I was trying to use imageloc :stuck_out_tongue:

Recommendations for the wiki (if I’m understanding this correctly):

  • the foundimage TOKEN page should link to “Pause Until” action
  • the found_image CONDITION page should explain the foundimage token
  • the “Pause Until” page has “found_image” as a condition but nothing about %FoundImage% as a result. Use of this should be an example, too, as it is extremely useful and confusing because of the token-vs-condition thing (to say nothing of the confusion introduced by the imageloc token if you’ve already been introduced to that :slight_smile: )

Thank you again for assistance!

1 Like

Argh, my code still is not working! I have the below code finding image in my Cerner-based medical record system. You can see that it is finding the image ("currently true"), but it's not getting the midx and midy results (the display text action shows the entire array followed by the text ".midx" for example).

Now I'm trying to calculate a midx and that doesn't work either (it will let me refer to the first element of FoundImage but doesn't like me referring to any others!):

What am I missing?

The issue you're running into is that %FoundImage% is a token, not a variable, and you're trying to use it in ways that only variables can be used. Fortunately, the solution is simple: just set a variable to %FoundImage% and use that in the actions instead, and everything should Just Work™:

Use FoundImage in Other Actions.kmactions (24.0 KB)

(you'll also notice that I used the .midx and .midy references in a %Calculate% token for the Display Text action, as that's the only way to perform calculations with variables in a standard text field)


Oh my. @peternlewis, this really highlights my earlier argument that things like FoundImage should be system variables rather than text tokens! Look what end users are going to have to figure out (the vast majority who would want to use such functionally will not!):

  • when something is a text token vs variable
  • .midx and .midy, which just work with the result of “Find Image on Screen,” will not work with foundimage! (And there’s nothing that makes clear that you are putting the result of “Find Image on Screen” in a variable, whereas FoundImage is a token which requires different syntax in multiple situations)
  • you have to assign foundimage to a variable for .midx and .midy to work (!!)–inherently not intuitive, AND another step every time you use it!

Also, in trying to do the most basic debugging, nobody [except the occasional genius like
@gglick] is going to figure out that it would take %Calculate% to get midx and midy :P…I see in retrospect, having some knowledge of programming, why that makes sense, but given how much Keyboard Maestro facilitates things just working, it seems like a miss that this is required :slight_smile:

Again, I now know how to make these things work (and am very grateful @gglick!), but passing on for the good of the platform and future users these ideas. :slight_smile: Maybe a good first-pass aid would be to have a text explanation of FoundImage show in the “Pause Until” action when the user selects condition “The Screen:”?

PS: if a user starts with example code that puts FoundImage in a variable, and finds .midx and .midy work, and then later writes a similar macro that does NOT work (because didn’t know the step of creating a variable based on FoundImage was necessary for those to work), it’s crazy-making! :scream:


Thanks for the kind words, @ajg23, but I promise you I’m not that smart :slightly_smiling_face:
After years of using KM, I’ve just come to intuitively recognize that text within percentage symbols in standard text fields (in other words, tokens, of which variables are really just a different kind) is treated differently than text outside of it, and once you have that kind of understanding, it’s not much of a leap to realize that array specifiers like .midx just aren’t going to work outside of the token syntax (although even there I might also have gotten stumped on how to access them in a text field if I hadn’t had experience using %Calculate% in a similar manner before).

As for the rest of the constructive criticisms you make about the non-intuitiveness of using tokens like %FoundImage%, I can’t and won’t speak for Peter (though as with many things with KM, I’m fairly certain there was a lot of thought that went into the decisions that led to the way things are now), but I can point out that a clear example of how to make use of found image coordinates in a variable is already on the wiki, in the page for Find Image on Screen:
The only real difference between the example given there with the Find Image on Screen action and the Pause Until Image is Found action you use in your macro is that if you want to use the latter, you need to manually add the step that lets you save the image’s coordinates to a variable in order to make them accessible in the other ways shown. For my money, I’d say it does make sense from a long-time KM user’s perspective, but there’s no doubt that KM’s learning curve and figuring out where and how to access many of its features is one of, if not the, biggest obstacle that new users run into.

Right, and I was using that and pulling what-hair-I-would-have-if-I-had-any out because the FoundImage token wasn’t acting like that very clear explanation on the wiki :skull_crossbones:

Gotcha. My mistake then! Yeah, in that case it just gets back to the ways variables can be used that tokens alone can’t, and you already covered that well in your last post :slightly_smiling_face:

I have addressed your recommendations in this new topic:
Wiki Update: Found Image Related Articles

Please review.