How to modify do something to many window which name star with same words

Hi,

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.

Thanks

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

If not, then replace starts with by contains.

1 Like

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.

Great! I check the formatting! But I don't know how to keep coloring format.

Thank you!

The syntax coloring is done by the forum script automatically – normally.

Maybe you have used indentation, instead of a fenced code block?

Try it like this:

```
<your code here>
<your code here>
```

If there is still no syntax coloring (or the wrong one), then add a language tag:

```applescript
<your code here>
<your code here>
```

I used the KM function "Copy as Text"

I try to copy here and Apple Script from KM

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

And here normal again. Seems to work!

1 Like

Great! And that “Copy as Text” creates those double line breaks too?


Back to the script: Did the try solution work for you? (This one.)

XNo! I used ``` In order to get proper color and format from a “Copy as text”.

About the try Statement. I didn’t try it! My interest in that code (this )was about this different synthax I tries to use and didn’t work:

click button "Render" of first window whose name starts with "Audio Suite" of application process "Pro Tools"

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