Searching Pop Up Menus in Pro Tools via Applescript?

Hey folks, having a bit of a head-scratcher here. I’m trying to script some stuff in Avid Pro Tools, and I need to get at a menu triggered by a pop up button.

UI Browser is confusing me a bit (the hierarchy to elements in the menu when using the screen reader is:

ELEMENT PATH (starting at leaf element): ((/not sure what this means/))
   menu item "User Time Stamp"  (menu item 6)
      menu (menu 1)
         menu item "Sort by"  (menu item 7)
            menu (menu -9223372036854775808
               [MISMATCH-different children]   application "Pro Tools"

Ideally, I’d need to be able to search one of these types of menus, as the items in them change a lot (I’ll be defining one of the menu items I’m looking for elsewhere in the script, through another part of Pro Tools).

Annoyingly the menus disappear if I try and do much of anything in UI Browser after opening them, so I’m not sure where to start. From what I can tell, they don’t seem to actually be contained within the Pro Tools process’ hierarchy.

Any thoughts?

The rest of my script currently looks like this (which is contained in a MASSIVE macro at the moment):

tell application "System Events" 
	set EditWindow to a reference to (every window of process "Pro Tools" whose name contains "Edit")
	set Aux1 to a reference to (every group of EditWindow whose name contains "Aux 1")
	set Aux1Name to a reference to pop up button 1 of Aux1
	click pop up button 1 of Aux1
end tell

It’s a bit more verbose than one would expect because I’m hoping to use this as a sort of framework for some other functions.

Dynamic menus can be a nightmare to script, as you are finding out.
Sorry I don't have a specific solution for you (I don't have the Avid Pro Tools app), but you may want to do a google search something like this:
AppleScript Avid Pro Tools

I found this one that looks really promising:
Automation AppleScripts for Pro Tools (Mac)

Good luck and let us know if you find something helpful.

Hi JM - yeah sadly I think I’m doing some things nobody else with Pro Tools has even bothered to attempt, so I’m a bit in the wilderness with it. There’s a lot of things I have ideas for, I just have to slam my head against the wall a bit until I’m comfortable with applescript again (been a few years/decades).

OK @mushoo, I get your point. It still may be worth a post or two to the Avid group. You might be surprised.

If you’re not getting anywhere, you might also try posting to these AppleScript forums/lists:

  1. Applescript-users list (ASUL)

@mushoo, how did you get on with this? I am a noob with applscripts but am slowly getting into scripting for Pro Tools and would love to be able to control things like telling the script to wait until the processing pop-up window has closed before continuing etc.

There's a couple things you can do, IIRC (not at the machine I usually do this stuff on, what with the quarantine and all).

One is to wrap the open-menu command in an 'ignoring application responses' and 'end ignoring' phrase (which seems to only sometimes work, and then sometimes you ALSO have to force restart the system events process?)

The other is to use (ugh) mouse clicks - I generally use applescript to get the screen position of the thing I want to click, then pass that along to KM to have it do the clicking. Once the menu is open, have KM 'type' the first few letters (you can use the 'use variable' action, I think) of the item you want to select, and then hit enter/return.

Which is fine for actually selecting pop-up menu items, but doesn't help AT ALL if you need to check if a popup menu item is enabled/disabled, though.

Hey, sorry for the slow reply, Thanks for responding. Yeah I started out with mouse clicks but am seeing how far I can delve into scripting. As you mentioned through I think it has to be a combo of scripting and then mouse clicks because of things like plugin windows being hidden / not at the forefront. So I'll keep digging and playing to see how far I can go! Many thanks!

Just found this thread here on EXACTLY what I've been trying to do for the past few hours.

Unfortunately I'm also stuck at the [MISMATCH-different children] part as well. I'm trying to create a script that will tell if "Suspend All Groups" is enabled/disabled which I'm sure is similar to what you want to do.

I found the attribute I want to get from it "MenuItemMarkChar" but that pesky dynamic menu item just doesn't seem to have a parent I guess?

Sadly no solutions here on this end, but if you ever did manage to do this I'd love to hear how!

I too have been attempting to click items on "dynamic menus" within Pro Tools for a couple years now. I'm able to scan the UI element with accessibility inspector, but can't seem to translate that into a useable Apple Script.

Here is a screenshot of the Accessibility Inspector:

And here is the, very simple, script that I had hoped would work:

tell application "System Events"
	click menu item "Link to source media (where possible)" of menu 1 of application "Pro Tools 2023.6"
end tell

Unfortunately, I've also had no success, but maybe someone else has an idea based on the above information.

I haven't had success returning the specific UI elements of a child pop up button like this, as pro tools reports the button's name as the current selection, and does not reveal the child menu items to system events. It sounds like you are probably doing the same thing, but in the import session data window, for example, if i want to set the Audio Media Options to "Force to target Session format" i'd use something like the following applescript.

tell application "System Events"
	if exists (process "Pro Tools") then
		tell process "Pro Tools"
			tell (1st window whose title contains "Import Session Data")
				tell group "Media Options"
					if exists (pop up button named "Force to target session format") then
						return "true"
						tell (static text "Audio Media Options:")
							return position
						end tell
					end if
				end tell
			end tell
		end tell
	end if
end tell

Then use the returned value to either continue with the script, or click the button and type "f" then "return" to select the desired menu item.

Additionally.... if you run the following (even with the pop up button open, applescript returns an empty string. So I think it's essentially a lost cause.

tell application "System Events"
	if exists (process "Pro Tools") then
		tell process "Pro Tools"
			tell (pop up button 2 of group named "Media Options" of window named "Import Session Data")
				return menu items
			end tell
		end tell
	end if
end tell

If you change return menu items to return UI elements, do you get anything? Just wondering if menu items are nested in another menu, or something similar.

Unfortunately not. Nothing shows up in UI browser either.