Making a script that will work with any window

Hello! I'm using Pro Tools, and I managed to get this script using UI Browser:

activate application "Pro Tools"

tell application "System Events"
   tell process "Pro Tools"
      click button "Track List pop-up" of window "Edit: test"
   end tell
end tell

It works great BUUUUT I see " of window "Edit: test"" in there and my Pro Tools sessions will have other names than "test".....is there a way to make this script more universal? Thanks!

If you want to invoke the script for which ever window is currently at the front, then you can change this line:

click button "Track List pop-up" of window "Edit: test"

to this:

click button "Track List pop-up" of the front window

provided there's a button named "Track List pop-up" in whichever window is the front window when your script is executed.

2 Likes

If you want to ensure it works even if a different window is at the front:

activate application "Pro Tools"
tell application "System Events"
	tell process "Pro Tools"
		
		set edit_window to title of first window whose title contains "Edit: "
		
		click button "Track List pop-up" of window edit_window
		
	end tell
end tell
1 Like

Nice! Thank you!!

Perfect! (As always!) Thank you!!