Clicking specific Chrome extension buttons

I've checked out this post from 2016 about clicking Chrome extension buttons, and I also followed the instruction and ran the script below in Script Editor.app

------------------------------------------------------------
# Get properties of buttons of toobar 1 in Chrome
------------------------------------------------------------
tell application "System Events"
  tell application process "Google Chrome"
    tell (first window whose subrole is "AXStandardWindow")
      tell toolbar 1
        properties of buttons
      end tell
    end tell
  end tell
end tell
------------------------------------------------------------

However, running this script returns with this script error message:
"System Events got an error: Can’t get toolbar 1 of window 1 of application process "Google Chrome" whose subrole = "AXStandardWindow". Invalid index."

Specifically, the extension buttons I would like to be able to press are 1Password and Extensity.

How can I accomplish that?

Thank you!

Hey @Llama_Lord,

Well, it looks like Google has altered Chrome's UI a bit...

Remove the extraneous button from the code and try this:

tell application "System Events"
   tell application process "Google Chrome"
      tell (first window whose subrole is "AXStandardWindow")
         tell group 1
            
            tell group "Extensions"
               
               tell button "1Password"
                  perform action "AXPress"
               end tell
               
               tell button "Extensity"
                  perform action "AXPress"
               end tell
               
            end tell
            
         end tell
      end tell
   end tell
end tell

It works on my macOS 10.12.6 system with Google Chrome 71.0.3578.20.

-Chris

1 Like

Yay it works!! Thank you!!

1 Like

Is that a Chrome Beta?

I just updated Chrome, and it shows:
Google Chrome 70.0.3538.77 (3538.77) on macOS 10.12.6

Yes.

-Chris

How would I find out the name for Click & Clean extension?

Hey Chris,

Run this in the Applescript Editor.app, and look in the result panel.

-Chris

tell application "System Events"
   tell application process "Google Chrome"
      tell (first window whose subrole is "AXStandardWindow")
         tell group 1
            tell group "Extensions"
               name of buttons
            end tell
         end tell
      end tell
   end tell
end tell

Thanks! Worked like a charm!

It's a browser history cleaner (Click&Clean) that I like to have clear out every 30 minutes since I am constantly referencing different dictionaries while working and after too long my browser starts lagging.

Unfortunately that button's name changes everytime a new page opens. It consists of "Visited Pages: (current number of page visits since last clean) Click&Clean".

Is there a way to tell it to just look for the one that contains Click&Clean much like the manipulate a window feature in KM?

Hey Chris,

Yep.

-Chris

tell application "System Events"
   tell application process "Google Chrome"
      tell (first window whose subrole is "AXStandardWindow")
         tell group 1
            
            tell group "Extensions"
               
               tell (first button whose name contains "Click&Clean")
                  perform action "AXPress"
               end tell
               
            end tell
            
         end tell
      end tell
   end tell
end tell

You're the man! This has really improved the reliability of my cleaner macro. Thank you!!

This Extensity extension allows me to quickly search for extensions that I wish to activate or deactivate, but pressing the arrow keys on my clipboard doesn't allow me to select the first search result. I can only do so using trackpad or mouse.

See photo

Is there a script I can use to select the first search result?

Thanks!

Very unlikely. The popup list is created by a Chrome extension, and therefore is not accessible by normal JavaScript-in-Browser.
Google claims this is for security.

Your only hope is to use Move or Click Mouse action based on found image. Use a unique image in the Dropdown, and then move the mouse down a sufficient amount to click on the desired item in the list.

Hey @Llama_Lord,

Nyet.

@JMichaelTX is on the money about that.

Also – since the Extensity UI is browser-created System Events can't see it to do UI-Scripting.

However – there are a couple of approaches available.

You can get the button position to index on and then use a Keyboard Maestro click action to click a fixed offset from that position.

tell application "System Events"
   tell application process "Google Chrome"
      tell (first window whose subrole is "AXStandardWindow")
         tell group 1
            
            tell group "Extensions"
               
               tell button "Extensity"
                  set extensityButtonPosition to its position
               end tell
               
            end tell
            
         end tell
      end tell
   end tell
end tell

tell application "Keyboard Maestro Engine"
   setvariable "buttonX" to item 1 of extensityButtonPosition
   setvariable "buttonY" to item 2 of extensityButtonPosition
end tell

Or you can index off the Extensity UI Window position once it's open.

tell application "System Events"
   tell application process "Google Chrome"
      set extensityWindowPosition to position of window 1
   end tell
end tell

tell application "Keyboard Maestro Engine"
   setvariable "buttonX" to item 1 of extensityWindowPosition
   setvariable "buttonY" to item 2 of extensityWindowPosition
end tell

Or you can use the Click at Found Image action to find the Extensions separator bar:

image

And click at an offset from that.

I would probably use one of the first two, because they'll be just a little faster.

-Chris

Thank you!!

1 Like

Hello CC,

thank you for excellent scripts to trigger my chrome extensions, including the Evernote Web Clipper.

I was wondering, from a UI Browser point of view, what exactly is the Evernote Web Clipper 'Window' ?

Is it a window ?

Is it accessible via UI Browser: is a script to click in the title field or some important info field (for which evernote does not provide shortcuts, contrary to other fields such as notebook and tags) possible using UI Browser info ?

thanks in advance for your time and help

UI Browser, and AppleScript, can only see the macOS window elements.
They can NOT see the HTML elements you see on a web page.
So, in the case of a web browser, the whole web page is seen as a "AXScrollArea".
They can NOT see the Evernote Clipper window, which is a window inside of an HTML frame.

Furthermore, as I have said elsewhere, Chrome (and Safari I think) will NOT allow JavaScript injection to get or set the HTML elements within a HTML frame.

Bottom line: Unless the web browser extension provides keyboard shortcuts, or other API, the only way to access the fields in this type of window is by KM Found Image, and then click at offsets to that found image.

1 Like

Now it's clear. thanks a lot. Yes, you told me before but I was ill at ease at asking you yet again.