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!
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!
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.
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.
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).
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.
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?
[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.
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.
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
--------------------------------------------------------------------------------
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.
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!