Debugging image matching issue

So, I was debugging a script where one part seemed to not be finding screen images that should be matched, and I was investigating this using the "Display" feature, that tells you whether, and where, an image matched on screen.

This behaved in a way I found non-intuitive (which is why it caught me out). Consider the following action:


The "If" block sets a variable if both the image is found onscreen, and the current variable is empty. I wanted to debug this, and turned on "Display", and run a test, and what I expected to see is the correctly matched image flash green on screen, so I could see the image was found, and therefore the problem I was having was not connected to failed image matching.

However, instead I see no matches, indicating that the image was not found on screen (leading me to try and figure out why). Even though the image actually was correct, and was matched OK.

Only if I cleared the variable currentPatchCategory, so that both if conditions were true, do I get a visible confirmation the image was found onscreen when testing this action - which makes the "Display" dependent somewhat on the if condition, and other variables, which is the non-intuitive behaviour I mention.

I would expect that the "Display" checkbox, to tell you whether an image was matched onscreen, should be local only to that screen image search step, and not be dependent on the other conditions in the If - because the Display is only there to visually show image matches, not to visually illustrate the sum of all your logic in that if block.

Has anyone else run into this?

(Ok, now I've posted this, I'm off to read the documentation again to see whether this behaviour is explained and expected.)


In a case where you are asking:

  • If all the conditions are true
    • condition A
    • condition B

Then Keyboard Maestro starts looking at both conditions simultaneously.

If condition B proves to be false, then the entire clause is false and so condition A is aborted and ignored.

So if you are saying "If screen contains image and variable is empty", and the variable is not empty, then the image matching process will barely get started before it is aborted.

So yes, this behaviour is entirely expected.


Thanks Peter - now I understand the behaviour better I won't get caught out by this again.

I was kinda assuming the if tests would be done sequentially from top to bottom, and that all tests would be done to evaluate the response (and hence, the image search would be performed, and I'd see the outcome).

Good to clear that up!

1 Like