Need help with "Found Image" for "Send to Bear" in Safari

I have never had much luck with Keyboard Maestro macros using "Find Image". And today is no different. I am trying to find a way to trigger the "Send to Bear" Safari Extension, as shown here

Now, granted, the target isn't very big, but the image looks pretty unique to me. Here's what I did:

I took a screenshot and cropped it to just this:

2020-03-22-17.01.45-Bear-Safari-Icon

and then I created a basic macro;

Since the Safari extension is near the top of the Safari window, I chose "Topmost".

Since I would always be doing this in a Safari window I chose in "the front window"

Even after dragging the "fuzziness" selector as far to the right as possible, Keyboard Maestro still does not find a match.

This seems to be what always happens to me when I try a "Found Image" macro.

What am I doing wrong, folks?

Personally I would try with an image that includes the entire button, and the first few millimetres of the URL bar. I tend to have better results with larger images. YMMV.

If I include more of the image, then Keyboard Maestro finds things that are not the image and (mis)matches against them.

Unless someone has another suggestion, I think I'm just going to move the Bear icon next to the "stoplight" icons at the top left and tell Keyboard Maestro to select the correct number of pixels from the top-left corner of the front window.

I've actually had very good luck with KM Found Image, but it is always my choice of last resort. :wink:

I don't have the Bear app or extension, but this script does work for Evernote, and it should work for Bear. Just CHANGE "Evernote" to "Bear" (assuming that "Bear" is part of the button's description) and put this script in a KM Execute an AppleScript action.

Since the below script does NOT know where you have located the Safari Extension Button, it loops through all buttons until it finds the specified keyword in the button description.
You can optimize this script to run faster by first running in Script Debugger 7, and getting the direct path to the button like this:

image
Then use this statement:

set oBtnExt to button 1 of UI element 1 of group 5 of toolbar 1 -- GET FROM SD

AppleScript to Click on Extension Button

property ptyScriptName : "Click on Extension Button in Safari"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2020-03-22"
property ptyScriptAuthor : "JMichaelTX"

tell application "Safari" to activate

tell application "System Events"
  tell process "Safari"
    
    set btnName to "Evernote" -- CHANGE to "Bear"    
    
    set oWin to window 1
    set foundBtn to false
    
    tell oWin
      
      --- Replace All of This ---
      tell toolbar 1
        repeat with oGroup in every group
          tell UI element 1 of oGroup
            repeat with oBtn in every button
              set btnDesc to description of oBtn
              if (btnDesc contains btnName) then
                set oBtnExt to contents of oBtn
                set foundBtn to true
                exit repeat
              end if
            end repeat
          end tell
          if foundBtn then exit repeat
        end repeat
      end tell
      
      --- WITH THIS    
      --- Once you run this in Script Debugger, you can get the next statement ---
      --   from the SD Explorer Panel
      
      --set oBtnExt to button 1 of UI element 1 of group 5 of toolbar 1 -- GET FROM SD
      
      tell oBtnExt to click
      
    end tell
    
  end tell
end tell

NOTE: This script is NOT bullet proof, and has NOT been tested with the Bear Extension.
But it should give you a good idea of how to achieve this.

Good luck.

This worked great (including the Script Debugger optimization). Thanks.

1 Like