KM11 Button Scan for objects that disappear when losing focus

Hello everyone,

I am just testing the new KM11 Button scanner and am impressed. I need to add a couple of new Macros for a couple of things i was too lazy to ^^

However, I've hit a bit of a problem. My goal was to make a macro that toggles my Gmail profile using the button scan function. Everything goes smoothly when I click on my profile icon in the top-right corner, revealing the dropdown menu. But here's the problem, when I switch over to Keyboard Maestro to scan the next button, the dropdown menu disappears.

Any of you know a workaround for this? Maybe a shortcut I'm not aware of? Fyi I'm aware of the image search method, but I'm keen on utilizing this shiny new feature :smiley:


Edit: I marked Peter's post as solution, as you can find titles for buttons via those tools. As it turns out, what I needed to interact with wasn't actually a button.
For another issue alias pressing a button that contains something check out Alexander's reply. You can use regex! :smiley:

You probably need to use a tool like UIElementInspector or AccessibilityInspector to look at the button and find it's title.

Or you can try just using the apparent title of the button.

1 Like

Thank you for recommending the AccessibilityInspector! After taking a closer look, I've noticed that the overlay mainly consists of HTML elements grouped together, with links rather than actual buttons for my other accounts. So, even if I were to scan specifically for buttons, they wouldn't show up....
As a workaround, I'll use image search for this particular task, although I must say the new button scan feature is damn cool :sunglasses:

One small suggestion for improvement: it would be quite useful if there were an option to "Press Button that Contains" certain text. This would come in handy in scenarios where the first part of a button's label remains constant, but the latter part changes like accounts, for instance. So a button labeled "Google-Account: James" might later change to "Google-Account: James work." Even though it's technically the same button and your script could still function, it would have to be manually adjusted or a if else case added.

You can actually emulate this as of now. By adding a ^ at the beginning of the button text field it will match using Regular expression. Press a Button [Keyboard Maestro Wiki]

^Google-Account: James would match (and in this case press) either “Google-Account: James” or “Google-Account: James work”, as both begins with the search string. If you’d want to press a button that 'contains' a string, not only 'beginning with' it, ^? seems to do this. (All though I am not proficient enough in regex to be sure if ^? is the expression to emulate 'contains' behaviour the most perfectly.)


Holy moly....I didn’t know that regex is possible in "press button". This is amazing! @peternlewis I am once again impressed!
Thank you @Alexander for pointing this out, that is very helpful and solves a couple of other cases I had :smiley: plus this one!



Any idea why many buttons in Logic Pro error like this?

Press Button “Description:channel mode” failed because the button is disabled

Example target button screenshot

This works:

activate application "Logic Pro X"
tell application "System Events"
tell process "Logic Pro X"
click button 13 of UI element 1 of UI element 1 of group 3 of list 1 of group 2 of window "Untitled - Tracks"
end tell
end tell

Unfortunately, because the position of the button in the UI element tree changes as you interact with the channel strip (add plugins/sends etc), this isn't a real solution. I was hopeful that the new button press functionality would allow me to click the button via its descriptor, but alas no such luck.

Regardless, I'm impressed with how quickly the action identifies compatible buttons via their descriptor. In my attempts to script that kind of thing, it's always been slllloooowwww. :snail:

Two possibilities - there are multiple matching buttons and the one you are referring to is disabled, or the button is disabled but nonetheless responds to the click action.

  1. There are only two buttons called Channel Mode in the front window (one for the current channel and one for its destination buss) and they both show up in the new button scanner.
  2. The button doesn't have an enabled/disabled state per se. It's a toggle between mono and stereo channel mode and the button press action sees it as 'disabled' in both states.

You'd have to check it in Accessibility Inspector.

It's altogether possible that the accessibility information for the button is not correct and does not match the actual state of the button.

Here's a macro to output readable UI Element Info:

Get Info for UI Element Under Mouse.kmmacros (23 KB)

Macro screenshot

Here's what I get from the Channel Mode button in Logic:

Keyboard Maestro defaults to enabled if the property is missing, so a missing value should not be an issue.

And yet:

2023-11-02 07:17:22 Action 15114233 failed: Press Button “Description:channel mode” failed because the button is disabled

Without access to the application so I can duplicate it, I can't say as to why.

Maybe there are more than one matching such elements (the scanning system would detect such things). Maybe the app returns different values at different times. I don't know I'm afraid.

If you can duplicate the issue on something I have access to, then I can take a further look.

Otherwise, I have added some debugging code for the next version that you can try which will report more of what it sees in this case.

1 Like

For the sake of completeness...

There are two and both are reported in the scan.

It's the same for every button (not in the toolbar) that I've tried. For the one in question, it returns one consistent value per visible state:

CleanShot 2023-11-03 at 07.37.13@2x

= stereo

CleanShot 2023-11-03 at 07.38.38@2x

= mono