Using "Press a button" with multiple buttons with the same name

Trying to write a macro that runs in a specific App window. (Finale 26)

There are multiple identical buttons and checkboxes in this window. Three buttons named "Select Font...", three buttons named "Position..." and several checkboxes named "Enclosure:"

How do I specify which of the buttons I need to press? Right now if I use "Press a button named 'Set Font...' " it opens all three sub-windows simultaneously.

In this case, I suppose I can use a 'click mouse' at a specific coordinate relative to the window, but with the checkboxes, I need to test their state with an If/Then to see if the button is off before I have the macro press it. In this case, the mouse coordinates will not work because I cannot test the button status first.

Is there a solution?

KM 9.0.5
MacOS 10.15.5
iMac 2019

That is very poor UI design.
So, just to make sure, do all of the "Set Font" buttons have EXACTLY the same name?

If so, then native KM Actions may not be able to help us in this case.

You could probably click on a specific button using AppleScript UI scripting, by selecting the proper button by element position, or by some internal ID.

The best tool to get the properties of a button is UI Browser, but it is expensive at ~$50. There may be a trial available.
But this tool by Chris @ccstone might be able to give us the data we need:
Front Window Analysis Tool Using AppleScript System Events (get window elements)

If you need help in identifying the button you want in this results list and/or using that in an AppleScript, then please save the BBEdit file (as a .py), zip it, and upload to forum, along with a screenshot of your app windows identifying the button you want to press.

1 Like

Here's a better idea: Use Script Debugger 7 .
If you don't already have it, you can get a free 30-day trial, and then it gracefully downgrades to SD7 Lite.

See this post by @ccstone: Using SD7 to View Front Window Elements

tell application "System Events"
  tell application process "Keyboard Maestro"
    set oWin to front window
  end tell
end tell

--- AFTER the window elements are displayed, drag the element of interest to the SD code panel
-- then usually replace the window title with "window 1"
-- This is the script you need in KM to press the "Recently Used" button.

tell application "System Events"
  tell its application process "Keyboard Maestro"
    --    tell its window "Keyboard Maestro Editor — @MOU Move Mouse to FrontMost Window When Window Changes"
    tell window 1 -- "Keyboard Maestro Editor — @MOU Move Mouse to FrontMost Window When Window Changes"
      tell its group 3
        tell its button "⌘" -- you could also use button 1
          action "AXPress"
        end tell
      end tell
    end tell
  end tell
end tell

SD7 Explore Panel

1 Like

I am struggling to visualise an app where all the buttons have the same name.
This like playing battleships where all the squares are blank, and it is pot luck whether you hit the correct square. :slight_smile:

Can you please post a screen shot of your design,
please give the buttons different names.

I am just a user of this program, not the designer.

I can use a Click Mouse action at the coordinates for the buttons. Primarily, I am stuck on how to test the state of the checkboxes.

That macro worked, and confirmed that the buttons are named the same. (Thank you for that - it has already come in handy when a checkbox Name from another window was not identical to the text beside it.)

I will try the Script Debugger suggestion and see what I get. I was ironically also unable to get the app's native scripting language to work with this window either.

In that case you may be able to use KM, since it looks like the checkboxes have unique names.

You can use an IF/THEN with a Button condition to determine if it is checked or not:

The condition can return true if:

  • a matching button exists.
  • a matching button does not exists.
  • a matching button is enabled.
  • no matching button is enabled.
  • a matching button exists but is disabled.
  • a button (usually a checkbox) exists and is off.
  • a button (usually a checkbox) exists and is on.
  • a button (usually a checkbox) exists and is mixed.

Yes, I've got all those covered in my macro. I was so focused on the two checkboxes that are identical "Enclosure..." that I didn't acknowledge that they are the ONLY two identical checkboxes. I can always make sure to manually check those in my workflow since all I need to do is remove the enclosures. At this point this morning I am mostly trying to figure it out just so I know how to do it for any future issues.

I tried a UI Element analyzer from another thread, and unfortunately, it looks like it's pulling the data from the first identical element, regardless of where my mouse pointer is. (I can tell because it pulls the position on the screen into the result and it only ever gives me the coordinates of the topmost identical element.)

Installing Script Debugger is my next shot. I was trying to avoid bringing another app into the mix if I could so I haven't started with that.

Using Script Debugger I can at least find out what the index of the two checkboxes are, and once I get more familiar with AppleScript I am sure I can find a way to check the value of it.

However, as I am a recent Mac user (switched from Windows in March because I figured, hey, I have the time to learn this now) my skills aren't quite there yet to write the AppleScript code needed.

I have successfully used the Click Mouse Action to get all of the buttons using their coordinates, and I've used an Until clause to Click at Found Image to find the Enclosure Checkboxes that are True. (Fortunately, I want them all set to false) This has been successful over 20 test attempts so I think it will work. Later on, once my AppleScript skills are better, I think I can write a script that checks the value of the checkboxes now that I know their index.

Thank you, Everyone, for your input.