I'm trying to create a simple script that checks to see if a Pro Tools UI group currently exists, and if not open it.
My script works great as long as I refer to the window as it's exact title, however if I try to access the window whose title contains "edit.. " (which would make the script universally usable) it errors out saying "Can't get group.. etc"
I've posted the basic code below. The line that is nested as a comment is the one that works.
Unfortunately this is not working:
window whose title contains "Edit: "
Thanks in advance for any insight as to what I am doing wrong.
tell application "System Events"
tell application process "Pro Tools"
tell (1st window whose title contains "Edit: ")
set SelectedTrack to title of button of UI element 2 of (1st row of table "Track List" whose selected is true)
set formattedString to text of SelectedTrack as string
set AppleScript's text item delimiters to "Selected. "
set theTextItems to every text item of formattedString
set AppleScript's text item delimiters to ""
set formattedString to theTextItems as string
end tell
# if not (exists (group "Inserts F-J" of group formattedString of window "Edit: TEST")) then
if not (exists (group "Inserts F-J" of group formattedString of window whose title contains "Edit: ")) then
tell menu bar item "View" of menu bar 1
click
click menu item "Edit Window Views" of menu 1
click menu item "Inserts F-J" of menu 1 of menu item "Edit Window Views" of menu 1
end tell
end if
end tell
end tell
I'm not a a computer to take a closer look at this right now, but perhaps you could insert your script between three “```” characters (minus quotation marks) which will make it keep its proper formatting. It will make it easier to read.
No doubt some of the real AppleScript gurus will chime in soon.
Unfortunately I don't have that app to test, nor am I super knowledgeable on AppleScript (but I've been learning a lot the last few months), so I can’t say anything with any real authority here, BUT... sometimes I have found that using an AppleScript variable works where an actual window name doesn’t. Especially when the window name contains special characters. So what I suggest is setting the Edit : bit as an AppleScript variable at the beginning of the script and referencing it that way. I have found some apps respond better to this method than others.
Modified AppleScript (click to expand/collapse)
set partialName to "Edit: "
tell application "System Events"
tell application process "Pro Tools"
tell (1st window whose title contains "Edit: ")
set SelectedTrack to title of button of UI element 2 of (1st row of table "Track List" whose selected is true)
set formattedString to text of SelectedTrack as string
set AppleScript's text item delimiters to "Selected. "
set theTextItems to every text item of formattedString
set AppleScript's text item delimiters to ""
set formattedString to theTextItems as string
end tell
# if not (exists (group "Inserts F-J" of group formattedString of window "Edit: TEST")) then
if not (exists (group "Inserts F-J" of group formattedString of window whose title contains "partialName")) then
tell menu bar item "View" of menu bar 1
click
click menu item "Edit Window Views" of menu 1
click menu item "Inserts F-J" of menu 1 of menu item "Edit Window Views" of menu 1
end tell
end if
end tell
end tell
The only change I made was adding set partialName to "Edit: " to the beginning and then referencing that later in the script. Again, this is just a theory, and until somebody far more knowledgable than me on AppleScript chimes in, it's worth trying.
It looks to me like your window title starts with “Edit:”. You can change that to “contains” below if needed.
AppleScript doesn't always do what you think it's going to do...
Unfortunately I don't have Pro Tools to test with, so here's one of the ways I'd try to get around the problem:
tell application "System Events"
tell application process "Pro Tools"
set winList to windows whose name starts with "Edit:"
if length of winList = 1 then
set targetWindow to item 1 of winList
tell targetWindow
# Stub
end tell
end if
end tell
end tell
I'm so glad you posted this, because just this morning I was testing a macro to automatically position my palettes next to a specific window, and I think this might be the best way to position one whose name changes (technically the name doesn’t change, but I always have 3 palettes open, the first two are always the same ones, the third depends on the country the person I am interpreting for is from).
I am running into an issue with it, but I'm gonna keep working on it and if I can't figure it out I'll make a new post so as not to hijack this thread.
Hey Chris, just wanted to say thanks again for this snippet. It is exactly what I needed to finish the script I was building yesterday.
As always, you're the man!
-Chris
--position Country palette
set palList to windows whose name starts with "Lionbridge Country"
if length of palList = 1 then
set pal3 to item 1 of palList
if pal3 exists then
tell pal3
set its position to {(mdXPos + mdXSize), (mdYPos + mdYSize - (palYSize * 3))}
end tell
end if
end if
You can probably speed that up a bit by doing something like this:
tell application "System Events"
tell application process "Script Debugger"
set winList to windows whose name starts with "Deselect"
if winList ≠{} then -- Assuming there won't be multiple hits needing more branching.
tell item 1 of winList to set its position to {0, 23}
end if
end tell
end tell
Thanks Chris! I don't really need to run this script very often, maybe once or twice a day (since once the palettes' position is set, they don't often change), BUT I am all about making things faster so I'll take a look at this tomorrow.