I wrote an Appe Script that is working on a floating window called "Audio Suite: Auto-Align Post", but the software can open many floating windows always called "Audio Suite: " and something each time different, depending the plugin is selected. How can change, for example this line, in order that it works with any "Audio Suite: " window?
click button "Render" of window "Audio Suite: Auto-Align Post" of application process "Pro Tools"
How do I say to do this to any windows that name starts with "Audio Suite: "???
Only 1 Audio Suite Window can be opened at one time.
In theory (I don’t have Pro Tools installed) this could work:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "System Events"
tell application process "Pro Tools"
tell (first window whose name starts with "Audio Suite: ")
tell button "Render" to click
end tell
end tell
end tell
Awesome! It works with both "starts with" and "contains". Really good!
I also try to re-use this in another way like the following but it doesn't work! WHY?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Pro Tools"
tell application "System Events"
if exists (button "Render" of first window whose name starts with "Audio Suite" of application process "Pro Tools") then
click button "Render" of first window whose name starts with "Audio Suite" of application process "Pro Tools"
else
end if
end tell
end tell
Since you don’t have any else action, it seems you just want to avoid errors when the button is not there. I would use a try block for this:
tell application "System Events"
tell application process "Pro Tools"
try
tell (first window whose name starts with "Audio Suite: ")
tell button "Render" to click
end tell
end try
end tell
end tell
So, if either the named window or the button doesn’t exist, it will silently do nothing. If you do want an error if the window doesn’t exist, but not if the button doesn’t exist, then put only the “click” line inside the try block.
Please check the formatting of your post. There are parts of code formatted as code block, and others are outside. Just click the Pencil icon for editing the post.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "System Events"
tell application process "Pro Tools"
tell (first window whose name starts with "Audio Suite: ")
tell button "Analyze" to click
end tell
end tell
end tell
The target window must be determined before you address its button. With parenthesis it should work:
tell application "System Events"
click button "Render" of (first window whose name starts with "Audio Suite") of application process "Pro Tools"
end tell