If Image Exists Execute the following actions

This seems like it should be simple for Keyboard Maestro to do but I am not finding this specifically. I would Keyboard Maestro to look for a specific image on the screen and if it exists then I would like to execute a key command. Currently having Keyboard Maestro click on the image makes the cursor go back and forth several times with restore original location and does’t always leave the image clicked.

“If Then Else” seems like the ticket but there is no option to look for an image that I can find. I have also tried “Find Image on Screen” and set it to a variable and then used the “Use Variable” action but there doesn’t seem to be a way to use that for running a key command or an AppleScript.

There is a Find Image on Screen condition, so you can use that.

You can use the Find Image action, and then the Variable condition to test whether the image was found. The variable will be empty if it was not found, and will contain the coordinates of the match if it was found.

AppleScript can access the variable values.

So there are numerous different ways to approach the problem, its just a matter of choosing one of them, but all the parts should be there for you using the Find Image or Variable conditions and/or the Find Image action.

I have spent quite a bit of time on this trying all sorts of things to no avail. If you use the Find Image action and set a variable for it, when Keyboard Maestro finds the image it doesn't set the variable to true. My guess is it is not suppose to but I am not sure how to use a variable once an image has been found.

From the documentation it looks like the "Find Image on Screen" action is to highlight it only, at least that is all I could find in the documentation.

Attached is an example Macro that maybe someone could modify that shows what I am trying to do in Cubase but uses the Finder as an example.

Example Help - If Finder Is Active - Make New Folder.kmmacros (34.9 KB)

Here is the Macro in Cubase which I am trying to actually use this for.
02 Set Quantize to Half Note.kmmacros (51.1 KB)

The Find Image action stores the location of the found image (x,y of the top left corner) in the variable, or sets it to the empty string if not found.

It is normally used as:

  • Find Image into Variable “Where”
  • If Variable Where is empty
    • Not Found
  • Else
    • Do stuff with variable Where.x and Where.y

Because your image (in the Example Help macro) includes text (which is anti-aliased in subtly different ways each time) and is in the menu bar (which is translucent), it requires a large amount of fuzz to match (for my Mac, it matched at 52% fuzz).

Thanks Peter, I probably am missing what the right action is that I should use to detect an image and when it is detected that it is there then do something else (execute a key command in my case). I tried to make an update to the macro based on your post. I think however you might have been more explaining how to use the Find Image command and in more words or less stating this isn't the command I want for finding an image and if an image is found on the screen then execute a set of actions. Is that correct? If so any further lead how I can accomplish this task in a macro?
If Finder Is Active - Make New Folder - Attempt 2.kmmacros (34.9 KB)

I have a dozen or more macros that I would like to implement this behavior with if it is possible. No idea how to do it with AppleScript and Keyboard Maestro but it sounds like from your first post that I don't need to use AppleScript.

Update: Okay I just found it, not sure how I missed the "If Then Else - The Screen:"but for anyone searching the forum here is an example macro that works.
If Finder Is Active - Make New Folder - Attempt 3.kmmacros (39.0 KB)

1 Like