Variable list, image search, pixel locations/coordinates

Hello again KMaestros!

So here goes. I have successfully found multiple images and logged their locations. I split the locations of those found images to two lists as seen here in my display box...

The next step Im looking for is having KM go through the list and find if one x,y coord is specifically white in color. I believe it would look something like this...

Once KM has identified that one of the x,y coords is white I want it to Command+Click all the other coords in the list (as instantaneously as possible). As always, thank you for the help!

One extra question. Is splitting the x/y coords needed? or is there another way of plugging those numbers back in from a single line? So instead of two lists, my one list would look like

116, 206
116, 303
116, 400
78, 498

and there would be a way to go line by line testing those coords for the white pixel?

Im looking at my screenshot now and realizing how wrong it is. Also, I think splitting to an x list and y list isnt really needed. I think I will restate my question as such...

In this screenshot trxy_list is a variable that contains this information...

116, 206
116, 303
116, 400
78, 498

From there how would I split the x/y coords (trackxy) so that I could search line by line for that white pixel?

You were very close. All you need is a "Search using Regular Expression" action before the "If Then Else" action. I never use Found Image actions myself anymore, so I could be off with this solution, but that said, I think something like this might do the trick:

For Each Image Coordinate.kmactions (3.0 KB)

Note that I set the "If Then Else" action to Command-Click if the pixel is not white because you said you wanted it to Command-Click every other coordinate in the list.

All that said, can I ask what your ultimate goal with clicking these coordinates is? The reason I never use Found Image actions myself anymore if I can help it is because they tend to be fragile and prone to failure, and I'm guessing that whatever it is you want to do, chances are good that there's a more efficient and accurate way to do it. What application(s) are you working in, and what is it that you're ultimately trying to accomplish?

1 Like

Just want to chip in here too. I also used found image action before but realised I could do most of these actions by moving the mouse relative to the window. I actually use this moving mouse action many many times a day as often apps don’t provide hotkeys for certain actions and thus I can automate things and make my own hotkeys this way. :slightly_smiling_face:

Thank you for your help! Splitting the x,y was perfect for me. Is that expression considered RegEx? Could you explain what those commands mean? the line specifically with (\d+) I mean. Also do you know of a good way to learn those commands?

I had to rework the white pixel part a bit but that was because of things I hadnt considered. I am not using found image for this part specifically anymore.

What I am trying to do is select/deselect tracks in my audio program Pro Tools. I have a separate hotkey setup to log the track positions on screen with ‘found image’ and that is how I get the specific x,y coordinates in that list. The logging has worked flawlessly for me so far and I am ultimately logging one pixel location for each track.

The state of the pixel being white means the track is selected. If its grey it means its not selected. Now that I have that working there are a few different commands I have in mind going forward.

Thank you again for your help. I figure getting a bit of regex into my brain will probably take my scripting to another level.

Thank you for your reply. The reason I chose found image was because the locations I am looking for on screen change depending on what you are doing. and often very frequently

No problem!

It was regex, and sure, I can take a crack at explaining them. You know how when you search for a number in most apps, you’re searching for an exact string of characters? For example, searching for the number “322” in a given document will only ever return instances where those three exact letters, “3,” “2,” and “2,” and only when all appear in that specific order. What regex does is let you search for an exact pattern of characters, which lets you search for a much wider array of things because the characters themselves can vary. The expression I used in the sample actions I showed you, (\d+), (\d+) is actually a very simple regex once you understand how it works. \d is the regex pattern for digits; by itself, it means that the regex will match exactly one digit, i.e. anything from 0 to 9. The + immediately after it means “look for at least one instance of the prior pattern, then keep matching as many instances of that pattern as you can find until you find a character that doesn’t match the pattern.” When used together, \d+ matches any sequence of digits that is at least 1 digit long until it finds a character that isn’t a digit. When this \d+ pattern is used twice, along with a comma and space in between to replicate how you’ve separated the two coordinates, it finds any two sequences of numbers in a single line of text separated by a comma and space, no matter what those numbers may be or how many of them there are in a single sequence.

The last part of this particular regex to explain is the parentheses around (\d+). These are used to capture, or save, the contents of the pattern within the parentheses. We can then use this captured pattern in KM using its “Search using Regular Expression” action to create variables consisting only of that pattern; in your case, a single sequence of numbers for both your X and Y coordinates.

If you want to know more and/or prefer a more visual explanation, you can see what I’m talking about in more detail here:
It will show you how the regex matches the first line of your sample text, 116, 206, and how each sequence of numbers is captured to its own group.

There is of course far, far more to regex then what I’ve described here, but hopefully I’ve made enough sense given your particular use case that it helps get you started. As for how to learn more about regex, there are lots and lots of resources out there, but there are two in particular that really helped me: the grep (another term for regex) chapter in the manual for BBEdit, chapter 8 (you can read that for free here: and a book called Mastering Regular Expressions, which was not free but was very helpful. If you have more questions, feel free to ask; there are plenty of people here far more knowledgeable and experienced with regex than me who I’m sure would also be glad to help.

At any rate, I’m glad you found a solution that’s working for you!


amazing, thank you that makes perfect sense.

Those resources look great perfect for what I need and I will be diving into them this week. KM is a fantastic program and the community here makes it 10X better. Thank you again and again.


With trackxy set to 116,206, in a calculation field, you can use trackxy.x and trackxy.y to get the two values, or trackxy[1] and trackxy[2] if you prefer. This will work in the Pixel condition or the Mouse Click action for example, since that is a calculation field.

See: Calculations user manual section.

1 Like