I have a Chrome extension with a button on the Chrome toolbar on the top right. I want to click it!
What is the best way to do this?
I tried using the Found Image macro but it couldn’t seem to find the image for some reason. Not sure if this is common or not, or whether its a feature of Chrome extension icons being non-visible to Keyboard Maestro.
Ideally, I don’t want to click just by location, because the icons may move if I add another Chrome extension so the click would miss!
Thanks,
Jon
Edit: I found my own solution now. If I click the Try button to find the image, it found the image on Chrome AND on Keyword Maestro Editor, so it was not unique and it didn’t know which to click. So, make sure KM is not displaying the image at the same time!
It’ll be significantly faster to use AppleScript for this if System Events can see the button.
Run this from the Script Editor.app.
Uncomment return name of buttons first,
If System Events sees the button you want to press then change “Inbox (7)” appropriately.
This is not a great example, because Gmail’s button’s title (“Inbox (7)”) will change according to how many emails are unread, but there are ways around that.
tell application "System Events"
tell application process "Google Chrome"
tell (first window whose subrole is "AXStandardWindow")
# Uncomment to get the names of the available buttons.
# return name of buttons
# Click the named button.
tell button "Inbox (7)"
perform action "AXPress"
end tell
end tell
end tell
end tell
If name of buttons does not work for you post a screenshot of the toolbar area of Chrome, so I can see the layout.
Thanks for that recommendation. I never used the Script Editor.app before. Am I supposed to paste in the entire code you put, uncomment return name of buttons and comments out the tell button code?
I tried just return name of buttons but it said undefined variable.
I've rewritten the scripts, so they should run without alteration.
Try the get-button-names script again.
If it doesn't work then post a screenshot of your toolbar that includes the button you're trying to press.
-Chris
------------------------------------------------------------
# Get the names of the available buttons:
------------------------------------------------------------
tell application "System Events"
tell application process "Google Chrome"
tell (first window whose subrole is "AXStandardWindow")
name of buttons
end tell
end tell
end tell
------------------------------------------------------------
------------------------------------------------------------
# Click the named button:
# In this case the “Bookmarks” button.
------------------------------------------------------------
tell application "System Events"
tell application process "Google Chrome"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
# Click the named button.
tell button "Bookmarks"
perform action "AXPress"
end tell
end tell
end tell
end tell
------------------------------------------------------------
I think OP is referring to the extensions to the right of the URL address bar... buttons like Evernote, 1Password, DevonThink, etc., not the Bookmarks bar. I am interested in this, too. Can your solution be modified to work on the extensions buttons? That would be great if it could! If not Chrome, maybe Safari?
Okay. Like the other scripts the first script will get you properties (instead of just names) of the buttons, except this time from toolbar 1.
I did it this way, because when I ran it here with just name NO names were returned (because the developers didn't provided for this level of accessibility).
Properties will let you see more info.
The second script is able to discover my 1Password button via its accessibility description, and this may or may not work for your button.
If you can't get this working then tell me what extension your using in Chrome, and I'll fix it.
-Chris
------------------------------------------------------------
# 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
------------------------------------------------------------
------------------------------------------------------------
# Press a button that doesn't have a name.
------------------------------------------------------------
tell application "System Events"
tell application process "Google Chrome"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
tell toolbar 1
tell (first button whose accessibility description is "1Password")
perform action "AXPress"
end tell
end tell
end tell
end tell
end tell
------------------------------------------------------------