Selecting Popup Menu in Pro Tools With JXA?

I have a AXPopUpButton that brings up a contectual menu if you click it. However, I can’t seem to access the menu with javascript applescript UIAutomation.

pop = item.popUpButtons.byName(“Select”)
pop.click()
delay(0.5)

Then the menu shows up on the screen. However, “pop.menus()”, “pop.menuItems()”, “pop.menus.menuItems()” all returns length of 0. How can I access the
popup menus using UIAutomation in javascript? Thanks!

Hey @Chi,

What app?

-Chris

It’s called Pro Tools by Avid.

Hi Chi, Pro Tools user here as well. (Until I learn Presonus Studio One Pro v.3). Which menu are you referring to?

There are many examples, but one of them is Track List Pop-Up button that looks like little arrow pointing down inside a circle on the top left of Mix windows next to the word tracks.

Application(“System Events”).applicationProcesses.byName(“Pro Tools”).windows.byName(“Mix: Session Name”).buttons.byName(“Track List pop-up”)
Thanks!

Hey Chi,

The basics of Analyzing UI elements with System Events.

Set up your script to click the button, so the menu is open and then get UI elements.

If there are none then you’re out of luck – the only way to select anything in that case is to type-select.

An example using the Keyboard Maestro Editor:

tell application "System Events"
   tell application process "Keyboard Maestro"
      tell window "Keyboard Maestro Editor"
         tell button 1 of group 5
            perform action "AXShowMenu" -- Open the History Button Menu.
            UI elements
         end tell
      end tell
   end tell
end tell

Place this in a script window in the Script Editor.app.

Then use a Keyboard Maestro macro to run this:

tell application "Script Editor"
   tell document 1
      execute
   end tell
end tell

With the Keyboard Maestro Editor frontmost.

Then look in the result pane of the Script Editor.

Repeat this exploratory process with Pro Tools.

-Chris

1 Like

Thanks Christopher for the reply.

I’m little confused.

I put the script you provided in the script editor.

Then I created a new macro, and have it execute the second script you provided.

tell application "Script Editor"
   tell document 1
      execute
   end tell
end tell

When I run that macro, it gives me choice of some macros I already created.

Script editor clicks a button in the KM editor.

Do I need to change it so that it clicks the popup button in Pro Tools instead of a button in the KM editor?

thanks,

Chi

Also, this is the result I get.

tell application "System Events"
   perform action "AXShowMenu" of button 1 of group 5 of window "Keyboard Maestro Editor" of application process "Keyboard Maestro"
   get every UI element of button 1 of group 5 of window "Keyboard Maestro Editor" of application process "Keyboard Maestro"
end tell

Result:
{}

Even though it popped up the history menu, but nothing seems to be in there.

Hey Chi,

As I mentioned the Keyboard Maestro Editor script is an example – an example of BOTH success and of failure. System Events can see and click the history button, but it can’t see the pop-up menu.

I don’t have Pro Tools to test with, so I can’t give you a definitive script.

That is precisely the point.

There are NO further UI elements to work with that System Events sees.

If you have the same issue with Pro Tools then you cannot proceed further using System Events and UI elements.

On the other hand if you can pop up the menu, you should be able to select an item using an Insert Text by Typing action (probably followed by a carriage return).

-Chris

Thanks again Christopher.

However, the test script you provided is supposed to spit out the menus structure for the KM editor in the script editor log, right? I get empty [] even though the menu popped up.

Is this El Capitan problem?

Thanks again,

Chi

As I said this is precisely the point.

GUI-Scripting is only as good as the APIs Apple provides (and whether the developer uses them properly).

-Chris

Ah got it. The Keyboard Maestro also improperly implemented the particular button according to apple API then? If the pop-up button was correctly implemented, the script you provided should spit out the menu, right? Thus, there’s nothing I can do using UI scripting other than simulate typing to choose a menu? Am I understanding this correctly?

Thanks!!!

[quote=“Chi, post:12, topic:4789”]
If the pop-up button was correctly implemented, the script you provided should spit out the menu, right?[/quote]

Hey Chi,

Good question. Peter’s been around the block a few times – I think it unlikely that he’d mess up a pop-up button.

I’m not a developer, so I don’t understand all the under-the-hood nuts-and-bolts of the Accessibility API.

Perhaps Peter will explain.

That’s correct – if System Events can’t see it then you can’t gui-script it.

In cases where I have to pop-up a menu with AppleScript (and System Events) and then type-select to get to a menu item I want to select, I generally prefer to use Keyboard Maestro to do the type-select part.

While you can insert text (type) with System Events it tends to be more susceptible to side-effects than Keyboard Maestro.

Side-effects caused by user hotkey presses for instance.

-Chris

Thanks! Hopefully Peter will chime in.

Chi

The menu is created dynamically, so it does not exist except when popped up.

Accessibility can no more see it when it is not popped up that you can visually see the menu when it is not popped up.

It works perfectly well with accessibility, it just wont work as some sort of end-run attempt to get at the macro execution history while the button is not pressed.

Hey Peter,

As far as I can tell you can’t get the macro list from the History button via Accessibility even after the menu has been opened.

This is not always the case with dynamically generated menus – a working example:

--------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2016/08/28 14:20
# dMod: 2016/08/28 14:32 
# Appl: System Events
# Task: Example of Working with a Dynamically Populated Menu.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Select, @Item, @Dynamically, @Populated, @Menu
--------------------------------------------------------------------------------

tell application "System Events"
   tell application process "Finder"
      set frontmost to true
      
      tell menu bar item "File" of menu bar 1
         perform action "AXPress"
         tell menu "File"
            tell menu item "Open With"
               perform action "AXPress"
               
               delay 0.5 --> Half a second may or may not be enough.
               # There is a longer initial delay IF the menu hasn't been opened since boot.
               
               tell menu "Open With"
                  # set miProps to properties of UI elements
                  select (first menu item whose name contains "Eddie")
               end tell
               
            end tell
         end tell
      end tell
      
   end tell
end tell

--------------------------------------------------------------------------------

-Chris

Thanks Peter. Even if I have the menu show up by holding down the button with mouse manually, AppleScript doesn’t seem to grab the list of the menu that just popped up.

Thanks for your help!

That is in the system menu bar, not in a popup button.

I got it to work in Text Edit. Here is a working example for a popup menu for font.

pop = Application("System Events").applicationProcesses.byName("TextEdit").windows()[0].groups[0].popUpButtons[0]
pop.click()
delay(0.5)
pop.entireContents()

If you copy those and run it in script editor as javascript with text edit open, you’ll see all the font choices in the log.

However, I can’t get the list of PopUpmenus for KM or Pro Tools even though they’re shown on the display.

Any thought?

Thank you for your help!

Chi

Still trying to figure out this pop-up menu. Why can I access text edit font pop-up, but not keyboard maestro mac history pop-up? Thanks for your help!