No internet connection
  1. Home
  2. Support

How to beat the inconsistency of scripts in SoundFlow?

By Jonas Kroon @Jonas_Kroon
    2023-10-17 07:26:40.996Z

    Hey guys,

    I must say, while I absolutely adore SoundFlow and the idea of streamlining Pro Tools with it, some of my experiences over the last few years have been very frustrating.

    My biggest issue, I find, is that scripts that I create or download from the store just work randomly. Sometimes they do what they indend to do, sometimes they don't do anything, and once in a while they just go crazy and do random things.

    Take my mix prep script (code below). It's a very simple script intended to select track color and output routing for a track. I have been tweaking it for years, because whenever I get it to work it only does so in a stable manner for a couple of weeks. Then some random stuff starts occuring and I have to troubleshoot. Once in a blue moon a Pro Tools or Mac OS update can be the culprit, coming in and breaking things, which is understandable, but most of the time that's not the reason. I'm not updating my system very often, but my SoundFlow scripts keep doing random stuff anyway.

    I have lost count of how many different error messages this simple script has generated over the past few years. Today it reached some kind of crazy peak by launching the Photos app instead of doing what it is intended to do. When I tried to replicate the problem it launched the Final Cut Pro X app instead. I mean, are you kidding me?

    I'm sorry to say I'm close to giving up. At this point, sadly, I'm wasting more time than I save.

    I know, I know, it's probably me, not SoundFlow. But please, why do I find it so hard to create scripts that work consistently?

    I have many scripts that act weirdly, but here is the one I mentioned earlier:

    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.invalidate();
    
    function mainWindowStatus() {
        if (sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked) {
            sf.ui.proTools.menuClick({
                menuPath: ["Window", "Edit"],
            });
            return "Mix";
        } else {
            return "Edit";
        }
    }
    
    function returnToStartingMainWindow(mainWindow) {
        if (mainWindow == "Mix") {
            sf.ui.proTools.menuClick({
                menuPath: ["Window", "Mix"],
            });
        }
    }
    
    function restoreLinkTrackAndEditSelection() {
        sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
    }
    
    function ensureLinkTrackAndEditSelectionIsActive() {
        if (!sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked) {
            sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
            return true;
        }
    }
    
    function main() {
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.invalidate();
    
        const startingWindow = mainWindowStatus();
        const waslinkTrackAndEditSelectionOff = ensureLinkTrackAndEditSelectionIsActive();
    
        sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection');
    
        sf.ui.proTools.colorsSelect({
            colorBrightness: "Medium",
            colorNumber: 10,
     });
    
        sf.ui.proTools.selectedTrack.trackInputSelect({
            inputPath: ["no input"],
            selectForAllSelectedTracks: true,
        });
    
        //Calling command "RS_Route Selected Tracks to Output" from package "Raphael Sepulveda Utilities"
        sf.soundflow.runCommand({
            commandId: 'user:ckl7wp2ch00027f10j3pssxnh:ckitegbf00006qm10ixs68zih',
            props: {
                outputPath: ["bus", "bus menu 1-128", "Snare (Stereo)"],
            }
        });
    
        if (waslinkTrackAndEditSelectionOff) restoreLinkTrackAndEditSelection();
        returnToStartingMainWindow(startingWindow);
    }
    
    main();
    

    All the best,

    Jonas

    Solved in post #35, click to view
    • 38 replies

    There are 38 replies. Estimated reading time: 80 minutes

    1. S
      SoundFlow Bot @soundflowbot
        2023-10-17 07:26:43.442Z

        Thanks for contacting SoundFlow support.

        Please note, that the best way to get help with a script, macro or other content installed from the Store or content that you've made yourself, is to select the script/macro, then click the red Need help button, and then click "Get help with this script or macro".
        By using this method, we will get access to more information and so should be able to help you quicker.
        You can read more about how this works here: bit.ly/sfscripthelp

        If you're seeing an error that isn't related to scripts or macros, and you think this is a bug in SoundFlow, please file a Help/Issue bug report.
        You can see how to do this by going to bit.ly/sfhelpissue

        1. Jonas Kroon @Jonas_Kroon
            2023-10-17 07:46:17.502Z

            Tried to do that.

            Got this:

            1. Did it put a feedback ZIP file on your Desktop? In that case, you can forward that to support@soundflow.org

              1. Jonas Kroon @Jonas_Kroon
                  2023-10-22 17:38:02.873Z

                  No, as far as I can see, it didn't.

            2. In reply toJonas_Kroon:
              Christian Scheuer @chrscheuer2023-10-17 07:54:01.124Z2023-10-18 08:14:18.494Z

              Hi Jonas,

              I'm sorry to hear that you're seeing instability. The way to troubleshoot these things is to try to narrow down exactly what part of the script is acting in an unexpected way. Of course that can be difficult if it happens apparently randomly, however, with some patience, it's usually possible to narrow down to something that has some degree of meaning. That's the idea of troubleshooting - to take the seemingly random and make sense of it.

              In your case, I don't see anything immediately wrong with your script, so we would have to dive deeper and try to figure out exactly when in the script the error occurs.
              There's many ways to try to approach that. For example, you could add log entries between lines of script code, so that you'd have a better idea of which line of code causes the error. Once you start narrowing it down, you'd have to try to look for which types of situations could be patterns that trigger the incorrect behavior. The more structured this search, the smaller amount of time you'd typically spend on it.

              Note that having other simultaneously running keyboard/mouse automation software is a general source of potential instability as they might be interfering with what SoundFlow is doing.

              Another way to approach troubleshooting is to try to isolate wrong behavior by ruling out:

              • triggers - different ways to launch the scripts
              • hardware - potentially conflicting hardware
              • configuration - different ways things might be configured that may trigger the wrong condition
              • software - other software that might be interfering

              Note that this process of ruling out is not intended as a way to try to solve the problem, but as a way of identifying the actual source of the problem out of the seemingly random sets of behaviors.

              Hopefully, if you're able to follow these routes, it will help you have a better understanding of what leads to certain problems. We'd be very happy to hear any findings you have, so we can use that to further improve the product.

              Lastly, I notice that you have not opened any new threads since December of 2021. I would highly encourage you to look for support whenever something is happening, as it's much easier to help with concrete scenarios of a script needing help, rather than a general feeling of inconsistency that has built up over time and thus we would no longer have access to any log files that could help explain any past issues.

              1. Jonas Kroon @Jonas_Kroon
                  2023-10-17 08:13:58.256Z

                  In your case, I don't see anything immediately wrong with your script, so we would have to dive deeper and try to figure out exactly when in the script the error occurs.
                  There's many ways to try to approach that. For example, you could add log entries between lines of script code, so that you'd have a better idea of which line of code causes the error. Once you start narrowing it down, you'd have to try to look for which types of situations could be patterns that trigger the incorrect behavior. The more structured this search, the smaller amount of time you'd typically spend on it.

                  Thanks, that's good advice. I'll try to find the time to troubleshoot more comprehensively. Unfortunately time is not always plentiful, which is why I wanted to use SoundFlow in the first place.

                  If you wouldn't mind, what would log entries look like? It seems like a good idea.

                  Lastly, I notice that you have not opened any new threads since December of 2021. I would highly encourage you to look for support whenever something is happening, as it's much easier to help with concrete scenarios of a script needing help, rather than a general feeling of inconsistency that has built up over time and thus we would no longer have access to any log files that could help explain any past issues.

                  That is a good observation, Christian. And point taken. I realise that voicing a general feeling of inconsistency is not the most constructive way to ask for support. I will try to ask more specifically and more often.

                  Unfortunately, as sound engineers, we are often working to deadlines / under pressure / with clients in the room, so whenever a script doesn't do what it is intended to do, the practical response is to just put it away and execute the process manually. In a perfect world there would be time to troubleshoot after a session while things are still fresh in memory, but in my experience I don't often find the time. It's a matter of priorities of course.

                  Thanks for your thoughts on this.

                  1. Thanks so much. I've asked our team to assist you with more details in the troubleshooting. Hopefully we can get to the bottom of this :)

                    What I do for logging is usually something like adding simple log('blabla'); statements. This is also called "instrumentation", or "instrumenting" the code - essentially allowing the code to report (debugging) progress to you as it runs.

                    For example something as simple as logging the name of the function and a sequential number – now you'll be able to on a screen recording to see what the last log entry was before the issue occurred. You can further add waits to space things apart, which may also help isolate the code that's misbehaving.

                        log(`main 1`);
                        sf.ui.proTools.appActivateMainWindow();
                        log(`main 2`);
                        sf.ui.proTools.invalidate();
                    
                        log(`main 3`);
                        const startingWindow = mainWindowStatus();
                        log(`main 4`);
                        const waslinkTrackAndEditSelectionOff = ensureLinkTrackAndEditSelectionIsActive();
                    
                        log(`main 5`);
                        sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection');
                    
                        log(`main 6`);
                        sf.ui.proTools.colorsSelect({
                            colorBrightness: "Medium",
                            colorNumber: 10,
                     });
                    
                        log(`main 7`);
                        sf.ui.proTools.selectedTrack.trackInputSelect({
                            inputPath: ["no input"],
                            selectForAllSelectedTracks: true,
                        });
                    
                    1. Adding waits is done by code like this (to wait 1000 milliseconds):

                      sf.wait({ intervalMs: 1000 });
                      
                • In reply toJonas_Kroon:
                  Jonas Kroon @Jonas_Kroon
                    2023-10-17 09:00:44.156Z

                    Thank you, Christian, that is very helpful.

                    I will give this a try.

                    1. In reply toJonas_Kroon:
                      Kitch Membery @Kitch2023-10-17 18:09:04.485Z

                      Hi @Jonas_Kroon,

                      Kitch here from the SoundFlow team. Hopefully, I can help you troubleshoot the root cause of the issue you are experiencing. :-)

                      As Christian mentioned, having other simultaneously running keyboard/mouse automation software is a general source of potential instability as those apps might be interfering with what SoundFlow is doing. Are you using any keyboard/mouse automation software in your setup (for example apps like Keyboard Maestro)?

                      Also, be sure to check that you have installed the most recent stable version of SoundFlow (currently SoundFlow 5.4.8) which can be downloaded and installed from my.soundflow.org/install.

                      Be sure to check out the "Known Issues" article from the following link.
                      https://soundflow.org/docs/getting-started/install-soundflow/known-issues which details some specific known issues that can sometimes cause problems with SoundFlow scripts/macros.

                      1. Jonas Kroon @Jonas_Kroon
                          2023-10-17 18:41:03.277Z

                          Thank you Kitch!

                          I'm not running any other automation software.

                          I had SoundFlow 5.4.7. Updating now.

                          1. Kitch Membery @Kitch2023-10-17 20:14:14.988Z

                            Thanks @Jonas_Kroon,

                            Are you using any hardware that has drivers installed on your system that may cause a conflict, for example, 3rd party keyboard or mouse drivers?

                            It may also be helpful to get a rundown of your Computer setup
                            What computer are you using?
                            What operating system are you running?
                            What version of Pro Tools are you on?

                            1. Jonas Kroon @Jonas_Kroon
                                2023-10-18 06:55:38.544Z

                                Thanks @Kitch.

                                I have an audio interface that has drivers installed. I'm pretty sure that's all.

                                System info:

                                Mac Mini M2 Pro (2023)
                                Mac OS Ventura 13.0
                                Pro Tools Ultimate 2023.6.0
                                SoundFlow 5.4.8
                                Apogee Symphony I/O MK2 audio interface with driver 0.11.4 and control software 0.5.11

                                After updating SoundFlow and running the script in a fresh Pro Tools session, it doesn't launch Photos or any of that, but it fails half-way through and throws the following error message:

                                18.10.2023 08:46:40.60 <info> [Backend]: Received run command: user:ckl7w2yd000007f103k4jdket:ckle36mc300075010n4xd0avm
                                
                                18.10.2023 08:46:40.60 <info> [Backend]: [ServerController] Running command from sfgui: 'Jonas Mix Prep SNARE' (user:ckl7w2yd000007f103k4jdket:ckle36mc300075010n4xd0avm)
                                >> Command: Jonas Mix Prep SNARE [user:ckl7w2yd000007f103k4jdket:ckle36mc300075010n4xd0avm]
                                
                                18.10.2023 08:46:40.80 <info> [Backend]: Checking for running apps with bundle 'com.avid.ProTools'
                                
                                18.10.2023 08:46:40.80 <info> [Backend]: NSArray.ArrayFromHandle count = 1
                                
                                18.10.2023 08:46:40.89 <info> [Backend]: Mouse current pos is: (1427,62109375, 1322,49609375)
                                Clicking with mouse here: (10, 60)
                                
                                18.10.2023 08:46:40.89 <info> [Backend]: Moving mouse back to: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:40.90 <info> [Backend]: Position is now: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:40.92 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                ProTools processID: 86420
                                
                                18.10.2023 08:46:40.92 <info> [Backend]: Pro Tools language: English
                                Checking for running apps with bundle 'com.avid.ProTools'
                                
                                18.10.2023 08:46:40.92 <info> [Backend]: NSArray.ArrayFromHandle count = 1
                                
                                18.10.2023 08:46:40.95 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                ProTools processID: 86420
                                
                                18.10.2023 08:46:40.95 <info> [Backend]: Pro Tools language: English
                                
                                18.10.2023 08:46:41.00 <info> [Backend]: Mouse current pos is: (1427,62109375, 1322,49609375)
                                Clicking with mouse here: (10, 60)
                                
                                18.10.2023 08:46:41.01 <info> [Backend]: Moving mouse back to: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:41.02 <info> [Backend]: Position is now: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:41.04 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                ProTools processID: 86420
                                
                                18.10.2023 08:46:41.04 <info> [Backend]: Pro Tools language: English
                                
                                18.10.2023 08:46:41.25 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                
                                18.10.2023 08:46:41.29 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                
                                18.10.2023 08:46:41.38 <info> [Backend]: Mouse current pos is: (1427,62109375, 1322,49609375)
                                Clicking with mouse here: (1443, 651)
                                
                                18.10.2023 08:46:41.38 <info> [Backend]: Moving back...
                                
                                18.10.2023 08:46:41.39 <info> [Backend]: Position is now: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:41.40 <info> [Backend]: PopupMenu full role:AXMenu
                                
                                18.10.2023 08:46:41.40 <info> [Backend]: NOT YET IN AX MODE
                                
                                18.10.2023 08:46:41.40 <info> [Backend]: Clicking popup menu with PT2022.5+ implementation
                                
                                18.10.2023 08:46:41.40 <info> [Backend]: Clicking popup menu element: Tracks
                                
                                18.10.2023 08:46:41.70 <info> [Backend]: Mouse current pos is: (1427,62109375, 1322,49609375)
                                Clicking with mouse here: (1659, 701)
                                
                                18.10.2023 08:46:41.71 <info> [Backend]: Moving mouse back to: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:41.72 <info> [Backend]: Position is now: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:41.92 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                
                                18.10.2023 08:46:41.96 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                
                                18.10.2023 08:46:42.02 <info> [Backend]: Mouse current pos is: (1427,62109375, 1322,49609375)
                                Clicking with mouse here: (428, 1613)
                                
                                18.10.2023 08:46:42.03 <info> [Backend]: Moving back...
                                
                                18.10.2023 08:46:42.03 <info> [Backend]: Position is now: (1427,62109375, 1322,49609375)
                                
                                18.10.2023 08:46:44.20 <info> [Backend]: Logging error in action (01) WaitForPopupMenuAction: Popup window was not found after waiting 2000 ms
                                Logging error in action (01) OpenPopupMenuFromElementAction: Popup menu was not found
                                Logging error in action (01) PopupMenuSelectAction: Could not open popup menu
                                
                                18.10.2023 08:46:44.20 <info> [Backend]: Logging error in action (01) TrackSelectInputAction: Could not select input menu item: 'no input'
                                !! Command Error: Jonas Mix Prep SNARE [user:ckl7w2yd000007f103k4jdket:ckle36mc300075010n4xd0avm]:
                                Could not select input menu item: 'no input' (Jonas Mix Prep SNARE: Line 48)
                                    Could not open popup menu
                                    Popup menu was not found
                                    Popup window was not found after waiting 2000 ms
                                
                                << Command: Jonas Mix Prep SNARE [user:ckl7w2yd000007f103k4jdket:ckle36mc300075010n4xd0avm]
                                

                                I haven't had the time to insert log entries or waits in the code yet, but I will do so shortly.

                                1. Chad Wahlbrink @Chad2023-10-18 16:09:42.073Z2023-10-25 20:40:07.530Z

                                  Thanks for the information @Jonas_Kroon. Try this script and let me know how it goes for you.

                                  This version of the script allows you to define your output path at the top of the script. Then it will set all selected tracks to the desired color, input to "no input," and output to the desired output path.

                                  I believe the reason you were seeing an error could have been that the track you were trying to adjust the input/output path of was not scrolled into focus, which is why I have added the selectedTrack.trackScrollToView(); command.

                                  I've also added comments to each step of this script to hopefully show how it works a bit more.

                                  
                                  let outputPath = ["bus", "bus menu 1-128", "Snare (Stereo)"];
                                  
                                  /// ↑ Define your Desired Output Path Here ↑ ///
                                  
                                  // Function to capture status of whether we are focused on the "Edit" or "Mix" window. 
                                  // Enables us to revert to Mix Window after we finish if necessary.
                                  function mainWindowStatus() {
                                      if (sf.ui.proTools.invalidate().getMenuItem('Window', 'Mix').isMenuChecked) {
                                          return "Mix";
                                      } else {
                                          return "Edit";
                                      }
                                  }
                                  
                                  // Function to Return to Mix Window if necessary
                                  function returnToStartingMainWindow(mainWindow) {
                                      if (mainWindow == "Mix") {
                                  
                                          sf.ui.proTools.menuClick({
                                              menuPath: ["Window", "Mix"],
                                          });
                                      }
                                  }
                                  
                                  // Function to restore Link Track and Edit Selection state if this was off.
                                  function restoreLinkTrackAndEditSelection() {
                                      sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                  }
                                  
                                  // Function to capture the state of the Link Track and Edit Selection mode as on or off represented as true or false;
                                  function ensureLinkTrackAndEditSelectionIsActive() {
                                      if (!sf.ui.proTools.invalidate().getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked) {
                                          sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                          return true;
                                      }
                                  }
                                  
                                  function main() {
                                      // Activate Main Window
                                      sf.ui.proTools.appActivateMainWindow();
                                      // reset the UI so SF has the most up-to-date information about current state
                                      sf.ui.proTools.invalidate();
                                  
                                      // Capture the Selected Track 
                                      let selectedTrack = sf.ui.proTools.selectedTrack.invalidate();
                                      // Scroll Selected Track to View
                                      selectedTrack.trackScrollToView();
                                      // reset the UI so SF has the most up-to-date information about current state
                                      sf.ui.proTools.invalidate();
                                  
                                      // Use our function to capture the main window status
                                      const startingWindow = mainWindowStatus();
                                  
                                      if (startingWindow == "Mix") {
                                          sf.ui.proTools.menuClick({
                                              menuPath: ["Window", "Edit"],
                                          });
                                      }
                                  
                                      // Use our function to capture the Link Track and Edit Selection Mode status
                                      const waslinkTrackAndEditSelectionOff = ensureLinkTrackAndEditSelectionIsActive();
                                  
                                      // Set the color of the selected tracks to Medium 10
                                      sf.ui.proTools.colorsSelect({
                                          colorBrightness: "Medium",
                                          colorNumber: 10,
                                      });
                                  
                                      // Set input to "no input"
                                      selectedTrack.trackInputSelect({
                                          inputPath: ["no input"],
                                          selectForAllSelectedTracks: true,
                                      });
                                  
                                      // Set input to output Path defined at top of the script
                                      selectedTrack.trackOutputSelect({
                                          outputPath: outputPath,
                                          selectForAllSelectedTracks: true,
                                      });
                                  
                                      // Restore the Link Track and Edit Selection Mode status
                                      if (waslinkTrackAndEditSelectionOff) restoreLinkTrackAndEditSelection();
                                  
                                      sf.ui.proTools.invalidate();
                                  
                                      // Restore main window status
                                      returnToStartingMainWindow(startingWindow);
                                  }
                                  
                                  main();
                                  
                                  1. Jonas Kroon @Jonas_Kroon
                                      2023-10-22 17:59:40.788Z

                                      Hey @Chad,

                                      Thanks for the script tweak!

                                      As far as I can see, this script successfully sets color and routing. It also seems to work even if the selected track is not scrolled into focus.

                                      It does not, however, take me back to the Mix window after executing.

                                      1. Jonas Kroon @Jonas_Kroon
                                          2023-10-25 17:09:05.122Z

                                          Hey @Chad,

                                          I tested this script a bit more.

                                          As I'm almost always running it from the Mix window, it is important to me that it returns there after executing its tasks in the Edit window. I can see that you have included the function in the code, which is great.

                                          Now, the weird thing is that the script manages to return to the Mix window about 30% of the time. The rest of the time it doesn't - it completes the other tasks and leaves me hanging in the Edit window.

                                          Now, this is the randomness that makes me scratch my head 😅

                                          I put log entries in the code and managed to capture the log file one of the times it didn't return to the Mix window.

                                          As far as I can see the error is not mentioned in the log. The last part of the script seems to execute the function meant to restore main window status to Mix Window, but fails to do so without reporting an error. This leads me to think maybe it didn't capture the window focus correctly to begin with?

                                          Any ideas?

                                          25.10.2023 18:55:57.14 <info> [Backend]: Received run command: user:ckl7w2yd000007f103k4jdket:clo1rd84w00002w10zeecp4tq
                                          
                                          25.10.2023 18:55:57.15 <info> [Backend]: [ServerController] Running command from sfgui: 'Jonas Mix Prep KICK 2.0' (user:ckl7w2yd000007f103k4jdket:clo1rd84w00002w10zeecp4tq)
                                          >> Command: Jonas Mix Prep KICK 2.0 [user:ckl7w2yd000007f103k4jdket:clo1rd84w00002w10zeecp4tq]
                                          [LOG] Defining output path
                                          [LOG] Establishing a function to capture status of whether we are focused on the Edit or Mix window
                                          [LOG] Establishing a function to return to the Mix window if necessary
                                          [LOG] Establishing a function to restore Link Track and Edit Selection state if this was off
                                          [LOG] Establishing a function to capture the state of Link Track and Edit selection
                                          [LOG] Activating main window
                                          Checking for running apps with bundle 'com.avid.ProTools'
                                          NSArray.ArrayFromHandle count = 1
                                          
                                          25.10.2023 18:55:57.34 <info> [Backend]: Mouse current pos is: (1485,2578125, 738,171875)
                                          Clicking with mouse here: (10, 60)
                                          Moving mouse back to: (1485,2578125, 738,171875)
                                          Position is now: (1485,2578125, 738,171875)
                                          [LOG] Resetting the UI so SF has the most up-to-date information about current state
                                          [LOG] Capturing the selected track(s)
                                          ProTools version: 23.6.0.110 class: PT2023_6
                                          ProTools processID: 32854
                                          Pro Tools language: English
                                          [LOG] Scroll selected track(s) to view
                                          
                                          25.10.2023 18:55:57.70 <info> [Backend]: Mouse current pos is: (1485,2578125, 738,171875)
                                          Clicking with mouse here: (72, 32)
                                          Moving mouse back to: (1485,2578125, 738,171875)
                                          Position is now: (1485,2578125, 738,171875)
                                          Pressing key: kVK_ANSI_P. Flags: Zero
                                          Pressing key: kVK_ANSI_Semicolon. Flags: Zero
                                          
                                          25.10.2023 18:55:57.88 <info> [Backend]: Pressing key: kVK_ANSI_P. Flags: Zero
                                          
                                          25.10.2023 18:55:58.10 <info> [Backend]: [LOG] Resetting the UI so SF has the most up-to-date information about current state
                                          
                                          25.10.2023 18:55:58.10 <info> [Backend]: [LOG] Capturing main window status
                                          
                                          25.10.2023 18:55:58.10 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                          ProTools processID: 32854
                                          
                                          25.10.2023 18:55:58.11 <info> [Backend]: Pro Tools language: English
                                          
                                          25.10.2023 18:55:58.11 <info> [Backend]: [LOG] Capturing Link Track and Edit Selection status
                                          
                                          25.10.2023 18:55:58.12 <info> [Backend]: [LOG] Setting the track color
                                          
                                          25.10.2023 18:55:58.19 <info> [Backend]: Mouse current pos is: (1485,2578125, 738,171875)
                                          Clicking with mouse here: (1396, 823)
                                          
                                          25.10.2023 18:55:58.19 <info> [Backend]: Moving mouse back to: (1485,2578125, 738,171875)
                                          
                                          25.10.2023 18:55:58.20 <info> [Backend]: Position is now: (1485,2578125, 738,171875)
                                          
                                          25.10.2023 18:55:58.20 <info> [Backend]: [LOG] Setting the input path
                                          
                                          25.10.2023 18:55:58.25 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                          
                                          25.10.2023 18:55:58.28 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                          
                                          25.10.2023 18:55:58.35 <info> [Backend]: Mouse current pos is: (1485,2578125, 738,171875)
                                          Clicking with mouse here: (503, 236)
                                          
                                          25.10.2023 18:55:58.36 <info> [Backend]: Moving back...
                                          
                                          25.10.2023 18:55:58.37 <info> [Backend]: Position is now: (1485,2578125, 738,171875)
                                          
                                          25.10.2023 18:55:58.48 <info> [Backend]: PopupMenu full role:AXMenu
                                          
                                          25.10.2023 18:55:58.48 <info> [Backend]: NOT YET IN AX MODE
                                          
                                          25.10.2023 18:55:58.49 <info> [Backend]: Clicking popup menu with PT2022.5+ implementation
                                          
                                          25.10.2023 18:55:58.49 <info> [Backend]: Clicking popup menu element: no input
                                          
                                          25.10.2023 18:55:58.49 <info> [Backend]: [LOG] Setting the output path
                                          
                                          25.10.2023 18:55:59.05 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                          
                                          25.10.2023 18:55:59.09 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                          
                                          25.10.2023 18:55:59.16 <info> [Backend]: Mouse current pos is: (1485,2578125, 738,171875)
                                          Clicking with mouse here: (503, 254)
                                          
                                          25.10.2023 18:55:59.16 <info> [Backend]: Moving back...
                                          
                                          25.10.2023 18:55:59.17 <info> [Backend]: Position is now: (1485,2578125, 738,171875)
                                          
                                          25.10.2023 18:55:59.19 <info> [Backend]: PopupMenu full role:AXMenu
                                          
                                          25.10.2023 18:55:59.19 <info> [Backend]: NOT YET IN AX MODE
                                          
                                          25.10.2023 18:55:59.23 <info> [Backend]: Clicking popup menu with PT2022.5+ implementation
                                          Clicking popup menu element: Kick (Stereo)
                                          
                                          25.10.2023 18:55:59.23 <info> [Backend]: [LOG] Restoring Link Track and Edit Selection mode status
                                          
                                          25.10.2023 18:55:59.23 <info> [Backend]: [LOG] Restoring main window status
                                          << Command: Jonas Mix Prep KICK 2.0 [user:ckl7w2yd000007f103k4jdket:clo1rd84w00002w10zeecp4tq]
                                          
                                          
                                          

                                          Thanks 😊

                                          1. Chad Wahlbrink @Chad2023-10-25 20:46:41.931Z

                                            Interesting, @Jonas_Kroon!

                                            I updated the script again and tested it from the mix window. (Copy and paste the updates from my original post linked above).

                                            It seems to be acting consistently on my machine.

                                            I added a few more sf.ui.proTools.invalidate() calls to make sure we are acting on the most recent "UI updates" - I have a hunch that is why the menu item was not being appropriately clicked. See the added invalidate() calls in lines 9 and 85 of the current script.

                                            I also separated switching to the Edit window in the first place out of the mainWindowStatus() function so that things are a bit more apparent in the main() function.

                                            Let me know how this version does for you, and we can try more tweaks if necessary!

                                            1. Jonas Kroon @Jonas_Kroon
                                                2023-10-26 13:44:54.382Z

                                                Hey @Chad,

                                                Thanks for that!

                                                Unfortunately I get the same result as before. The script fails to re-focus the Mix window most of the time.

                                                I notice a few errors in the log. They are not new; they were present in the last version also. I don't think they are relevant to the window focusing issue, but as you can see, there are two "Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement" reported during the "Set Input Path" sequence and two more during the "Set Output Path" sequence. However, the script successfully sets the paths every time, so I don't know what the errors are about.
                                                I also have no idea why the window focusing is not working.
                                                Which versions of Mac OS and Pro Tools are you testing on?

                                                
                                                26.10.2023 15:30:17.95 <info> [Backend]: Received run command: user:ckl7w2yd000007f103k4jdket:clo68ob0300001y105dtd06u3
                                                
                                                26.10.2023 15:30:17.96 <info> [Backend]: [ServerController] Running command from sfgui: 'Jonas Mix Prep KICK 2.1' (user:ckl7w2yd000007f103k4jdket:clo68ob0300001y105dtd06u3)
                                                >> Command: Jonas Mix Prep KICK 2.1 [user:ckl7w2yd000007f103k4jdket:clo68ob0300001y105dtd06u3]
                                                [LOG] Starting script Jonas Mix Prep KICK 2.1...
                                                [LOG] Defining output path...
                                                [LOG] Establishing a function to capture status of whether we are focused on the Edit or Mix window...
                                                [LOG] Establishing a function to return to the Mix window if necessary...
                                                [LOG] Establishing a function to restore Link Track and Edit Selection state if this was off...
                                                [LOG] Establishing a function to capture the state of the Link Track and Edit Selection mode as on or off represented as true or false...
                                                [LOG] Activating main window...
                                                Checking for running apps with bundle 'com.avid.ProTools'
                                                NSArray.ArrayFromHandle count = 1
                                                
                                                26.10.2023 15:30:18.16 <info> [Backend]: Mouse current pos is: (1952,0234375, 86,58984375)
                                                Clicking with mouse here: (12, 62)
                                                Moving mouse back to: (1952,0234375, 86,58984375)
                                                Position is now: (1952,0234375, 86,58984375)
                                                [LOG] Resetting the UI so SF has the most up-to-date information about current state...
                                                [LOG] Capturing the selected track(s)...
                                                ProTools version: 23.6.0.110 class: PT2023_6
                                                ProTools processID: 978
                                                Pro Tools language: English
                                                [LOG] Scrolling the selected track(s) to view...
                                                
                                                26.10.2023 15:30:18.52 <info> [Backend]: [LOG] Resetting the UI so SF has the most up-to-date information about current state...
                                                [LOG] Using our function to capture main window status...
                                                ProTools version: 23.6.0.110 class: PT2023_6
                                                ProTools processID: 978
                                                Pro Tools language: English
                                                [LOG] Using our function to capture Link Track and Edit Selection mode status...
                                                ProTools version: 23.6.0.110 class: PT2023_6
                                                ProTools processID: 978
                                                Pro Tools language: English
                                                [LOG] Setting the color of the selected track(s)...
                                                Mouse current pos is: (1952,0234375, 86,58984375)
                                                Clicking with mouse here: (1772, 816)
                                                Moving mouse back to: (1952,0234375, 86,58984375)
                                                Position is now: (1952,0234375, 86,58984375)
                                                [LOG] Setting the input path of the selected track(s)...
                                                Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                                Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                                Mouse current pos is: (1952,0234375, 86,58984375)
                                                Clicking with mouse here: (503, 1109)
                                                Moving back...
                                                Position is now: (1952,0234375, 86,58984375)
                                                PopupMenu full role:AXMenu
                                                NOT YET IN AX MODE
                                                Clicking popup menu with PT2022.5+ implementation
                                                Clicking popup menu element: no input
                                                [LOG] Setting the output path of the selected track(s)...
                                                
                                                26.10.2023 15:30:19.01 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                                
                                                26.10.2023 15:30:19.05 <info> [Backend]: Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement
                                                
                                                26.10.2023 15:30:19.11 <info> [Backend]: Mouse current pos is: (1952,0234375, 86,58984375)
                                                Clicking with mouse here: (503, 1127)
                                                
                                                26.10.2023 15:30:19.12 <info> [Backend]: Moving back...
                                                
                                                26.10.2023 15:30:19.12 <info> [Backend]: Position is now: (1952,0234375, 86,58984375)
                                                
                                                26.10.2023 15:30:19.15 <info> [Backend]: PopupMenu full role:AXMenu
                                                
                                                26.10.2023 15:30:19.15 <info> [Backend]: NOT YET IN AX MODE
                                                
                                                26.10.2023 15:30:19.19 <info> [Backend]: Clicking popup menu with PT2022.5+ implementation
                                                Clicking popup menu element: Kick (Stereo)
                                                
                                                26.10.2023 15:30:19.19 <info> [Backend]: [LOG] Restoring the Link Track and Edit Selection mode status...
                                                
                                                26.10.2023 15:30:19.19 <info> [Backend]: [LOG] Restoring main window status...
                                                << Command: Jonas Mix Prep KICK 2.1 [user:ckl7w2yd000007f103k4jdket:clo68ob0300001y105dtd06u3]
                                                
                                                26.10.2023 15:30:20.36 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                                ProTools processID: 978
                                                
                                                26.10.2023 15:30:20.36 <info> [Backend]: Pro Tools language: English
                                                
                                                26.10.2023 15:30:20.36 <info> [Backend]: ProTools version: 23.6.0.110 class: PT2023_6
                                                ProTools processID: 978
                                                
                                                26.10.2023 15:30:20.36 <info> [Backend]: Pro Tools language: English
                                                
                                        • In reply toJonas_Kroon:
                                          Kitch Membery @Kitch2023-10-18 17:49:08.824Z

                                          Thanks for providing that information @Jonas_Kroon.

                                          Nothing looks out of order with your computer setup.

                                          I've also looked at your account and don't see any SoundFlow trigger conflicts.

                                          To double-check though, did you review the "Known Issues" article from the following link? https://soundflow.org/docs/getting-started/install-soundflow/known-issues

                                          Next time you experience an issue with this script or other scripts/macros, it's best to use the Script Help workflow bit.ly/sfscripthelp. This will gather all the information needed for us and the SoundFlow community to troubleshoot the issue further.

                                          Hopefully, the script @Chad's share will have improved reliability. Note this kind of script could be made into a command template where you can have presets for each output path, color, etc. That way you'd only need to keep one script up to date. We hold a Zoom hangout on Wednesdays so feel free to join us https://soundflow.org/hangout, in the hangout I'd be happy to walk you through how to create a command template from this.

                                          1. Jonas Kroon @Jonas_Kroon
                                              2023-10-22 17:43:14.279Z

                                              Hey @Kitch,

                                              To double-check though, did you review the "Known Issues" article from the following link? https://soundflow.org/docs/getting-started/install-soundflow/known-issues

                                              Yes, I did, thanks for the heads-up. I should be all good there.

                                              Next time you experience an issue with this script or other scripts/macros, it's best to use the Script Help workflow bit.ly/sfscripthelp. This will gather all the information needed for us and the SoundFlow community to troubleshoot the issue further.

                                              As mentioned earlier in the thread, I did exactly that, but got an error message.

                                              Hopefully, the script @Chad's share will have improved reliability.

                                              I'll give it a try and report back :)

                                    • In reply toJonas_Kroon:
                                      Chad Wahlbrink @Chad2023-10-26 15:01:17.335Z2023-10-26 19:39:51.611Z

                                      Hey @Jonas_Kroon,

                                      Responding to your post here.

                                      I had previously tested on macOS 12.7, Pro Tools 23.09, SoundFlow 5.4.8.
                                      I also just tested on macOS 13.5.2, Pro Tools 23.09, SoundFlow 5.4.8.

                                      
                                      
                                      let targetOutputPath = "Bus 1-2 (Stereo)";
                                      
                                      /// ↑ Define your Desired Output Path Here ↑ ///
                                      
                                      // Function to capture status of whether we are focused on the "Edit" or "Mix" window. 
                                      // Enables us to revert to Mix Window after we finish if necessary.
                                      function mainWindowStatus() {
                                          if (sf.ui.proTools.invalidate().getMenuItem('Window', 'Mix').getString('AXMenuItemMarkChar') == '✓') {
                                              return "Mix";
                                          } else {
                                              return "Edit";
                                          }
                                      }
                                      
                                      // Function to capture the state of the Link Track and Edit Selection mode as on or off represented as true or false;
                                      function waslinkTrackAndEditSelectionOff() {
                                          if (!sf.ui.proTools.invalidate().getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked) {
                                              return true;
                                          } else {
                                              return false;
                                          }
                                      }
                                      
                                      function main() {
                                          // Activate Main Window
                                          sf.ui.proTools.appActivate();
                                      
                                          // Use our function to capture the main window status
                                          let startingWindow = mainWindowStatus();
                                          // Use our function to capture the Link Track and Edit Selection Mode status and turn it on.
                                          let linkTrackAndEditSelectionOff = waslinkTrackAndEditSelectionOff();
                                      
                                          try {
                                              // Go to Edit 
                                              if (startingWindow == "Mix") {
                                                  sf.ui.proTools.menuClick({
                                                      menuPath: ["Window", "Edit"],
                                                  });
                                              }
                                      
                                              // First store the selected tracks
                                              let selectedTracks = sf.ui.proTools.invalidate().trackGetSelectedTracks().trackHeaders.map(t => t.normalizedTrackName);
                                      
                                              // If Track and Edit Selection was off, Turn it on. 
                                              if (linkTrackAndEditSelectionOff) {
                                                  sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                              }
                                      
                                              // Select the top most track
                                              sf.ui.proTools.trackSelectByName({ names: [selectedTracks[0]], deselectOthers: true });
                                      
                                              // Scroll to the top most track
                                              sf.ui.proTools.selectedTrack.invalidate().trackScrollToView();
                                      
                                              // Select all of our tracks
                                              sf.ui.proTools.trackSelectByName({ names: selectedTracks, deselectOthers: true });
                                      
                                              // reset the UI so SF has the most up-to-date information about current state
                                              sf.ui.proTools.invalidate();
                                      
                                              // Set the color of the selected tracks to Medium 10
                                              sf.ui.proTools.colorsSelect({
                                                  colorBrightness: "Medium",
                                                  colorNumber: 10,
                                              });
                                              
                                              // small wait
                                              sf.wait({ intervalMs: 50 });
                                      
                                              // Set input to "no input"
                                              sf.ui.proTools.invalidate().selectedTrack.trackInputSelect({
                                                  inputPath: ["no input"],
                                                  selectForAllSelectedTracks: true,
                                              });
                                      
                                              // Set input to output Path defined at top of the script
                                              sf.ui.proTools.invalidate().selectedTrack.trackOutputSelect({
                                                  outputSelector: menuItems => menuItems.filter(mi => mi.path[mi.path.length - 1] === targetOutputPath)[0],
                                                  selectForAllSelectedTracks: true,
                                              });
                                      
                                          } finally {
                                              // Restore the Link Track and Edit Selection Mode status
                                              if (linkTrackAndEditSelectionOff && sf.ui.proTools.invalidate().getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked) {
                                                  sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                              }
                                      
                                              // Restore main window status
                                              if (startingWindow == "Mix" && sf.ui.proTools.invalidate().getMenuItem('Window', 'Mix').getString('AXMenuItemMarkChar') !== '✓') {
                                      
                                                  sf.ui.proTools.menuClick({
                                                      menuPath: ["Window", "Mix"],
                                                  });
                                              }
                                          }
                                      }
                                      
                                      main();
                                      
                                      1. Jonas Kroon @Jonas_Kroon
                                          2023-10-26 18:36:53.739Z

                                          Hey @Chad,
                                          I really appreciate the work you are doing here. Thank you so much. I'm learning from watching you attack the problem from different angles.
                                          Unfortunately it still won't work. I can see the Edit window kind of blink at the end of the script, but it still doesn't focus the Mix window.
                                          Now the good news: In an act of desperation I went back to my original script and added the selectedTrack.trackScrollToView(); from your script, and voila! - It seems to work.
                                          For setting the output path this script makes use of the RS_Route Selected Tracks to Output script from @raphaelsepulveda 's Utilities package, but apart from that it looks rather similar to your first attempt. I will have to compare them more thoroughly, but at first glance this script seems to use much of the same langauge for handling window focus as yours did.

                                          Here's the one that's working:

                                          sf.ui.proTools.appActivateMainWindow();
                                          sf.ui.proTools.invalidate();
                                          
                                          function mainWindowStatus() {
                                              if (sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked) {
                                                  sf.ui.proTools.menuClick({
                                                      menuPath: ["Window", "Edit"],
                                                  });
                                                  return "Mix";
                                              } else {
                                                  return "Edit";
                                              }
                                          }
                                          
                                          function returnToStartingMainWindow(mainWindow) {
                                              if (mainWindow == "Mix") {
                                                  sf.ui.proTools.menuClick({
                                                      menuPath: ["Window", "Mix"],
                                                  });
                                              }
                                          }
                                          
                                          function restoreLinkTrackAndEditSelection() {
                                              sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                          }
                                          
                                          function ensureLinkTrackAndEditSelectionIsActive() {
                                              if (!sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked) {
                                                  sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').elementClick();
                                                  return true;
                                              }
                                          }
                                          
                                          function main() {
                                              sf.ui.proTools.appActivateMainWindow();
                                              sf.ui.proTools.invalidate();
                                          
                                              const startingWindow = mainWindowStatus();
                                              const waslinkTrackAndEditSelectionOff = ensureLinkTrackAndEditSelectionIsActive();
                                          
                                              sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection');
                                          
                                              // Capture the selected track
                                              let selectedTrack = sf.ui.proTools.selectedTrack.invalidate();
                                              
                                              // Scroll the selected track into view in the Edit window
                                              selectedTrack.trackScrollToView();
                                          
                                              sf.ui.proTools.colorsSelect({
                                                  colorBrightness: "Dark",
                                                  colorNumber: 6,
                                              });
                                          
                                              sf.ui.proTools.selectedTrack.trackInputSelect({
                                                  inputPath: ["no input"],
                                                  selectForAllSelectedTracks: true,
                                              });
                                          
                                              // Calling command "RS_Route Selected Tracks to Output" from package "Raphael Sepulveda Utilities"
                                              sf.soundflow.runCommand({
                                                  commandId: 'user:ckl7wp2ch00027f10j3pssxnh:ckitegbf00006qm10ixs68zih',
                                                  props: {
                                                      outputPath: ["bus", "bus menu 1-128", "Kick (Stereo)"],
                                                  }
                                              });
                                          
                                              if (waslinkTrackAndEditSelectionOff) restoreLinkTrackAndEditSelection();
                                              returnToStartingMainWindow(startingWindow);
                                          
                                          }
                                          
                                          main();
                                          
                                          1. Chad Wahlbrink @Chad2023-10-26 19:24:59.598Z

                                            Great, @Jonas_Kroon! I'm glad you found something that is working for you.

                                            I am curious if the most recent version of the script here works: How to beat the inconsistency of scripts in SoundFlow? #post-22

                                            I changed the code in that post a few times but just confirmed it worked on Monterey and Ventura, as far as I can tell. With the added benefit of not needing to provide a full path to a bus, just the bus name ("Kick (Stereo)" can be found regardless of bus path, etc.).

                                            If the script you shared accomplishes your goals, then great. I am typically not working from the "Mix" window, so I actually learned a bit from troubleshooting this! As I mentioned below, if you run into issues with the intended track selection changing on you, I'd suggest changing sf.ui.proTools.appActivateMainWindow(); to sf.ui.proTools.appActivate();. I also noticed that the track selection could be changed erroneously if "Link Track and Edit Selection" is off when the script is started - this is a result of the track selection becoming the tracks with a current edit selection when this option is turned on.

                                            Happy automating 👏

                                            1. Jonas Kroon @Jonas_Kroon
                                                2023-10-26 19:46:02.482Z

                                                Just to complete the testing:
                                                The slightly modified original script that is the one working most consistently at the moment, just succeeded 24 out of 25 times here.
                                                The one time it didn't work, it reported the following error:

                                                26.10.2023 21:39:28.68 <info> [Backend]: Logging error in action (01) ClickMenuAction: Could not find menu item: Window->Mix
                                                !! Command Error: Jonas Mix Prep KICK [user:ckl7w2yd000007f103k4jdket:ckle2ssu800055010biesgl5i]:
                                                Could not find menu item: Window->Mix (Jonas Mix Prep KICK: Line 17)
                                                

                                                So it was a different problem than before. For some reason, in 1 out of 25 attempts, the script couldn't find the window item 'Mix'.
                                                Well, I'm going to leave this to rest for now. I have a script that is almost perfectly working.

                                                For now :)

                                                Next mission is to have the script move the selected tracks into the right place. But that is another adventure.

                                                Thanks for your help @Chad, it's much appreciated!

                                                1. Chad Wahlbrink @Chad2023-10-26 20:05:49.140Z

                                                  That's great, @Jonas_Kroon ! Happy to help!

                                            2. In reply toChad:
                                              Chad Wahlbrink @Chad2023-10-26 18:52:07.726Z

                                              @Jonas_Kroon, I swapped the above script again! Seems solid on my system.

                                              It will also now allow you to just name the bus, instead of giving a full path... That way it can find the "Snare (Stereo)" bus in any bus menu, in sessions big or small.

                                              The first one I posted earlier this morning was overly complex.

                                              So, I think I found a few issues in my scripting logic on those earlier versions.

                                              One interesting note is that when using sf.ui.proTools.appActivateMainWindow() from the "Mix" window, it seems like it's possible for that action to change the track selection since SoundFlow is effectly clicking in the upper left corner of that window. It's likely better to use sf.ui.proTools.appActivate if the "Mix" window is frontmost!

                                              1. Jonas Kroon @Jonas_Kroon
                                                  2023-10-26 19:26:46.787Z

                                                  Thanks @Chad,

                                                  This latest script worked 22 out of 25 times here.

                                                  1 of the 3 times it didn't work, it reported no error but failed to return to the Mix window.

                                                  2 of the 3 times it didn't work, it reported the following error:

                                                  26.10.2023 21:14:10.51 <info> [Backend]: Logging error in action (01) PopupMenuSelectAction: Could not click popup menu item
                                                  Logging error in action (01) TrackSelectInputAction: Could not select input menu item: 'no input'
                                                  
                                                  26.10.2023 21:14:10.51 <info> [Backend]: !! Command Error: Jonas Mix Prep KICK 2.3 [user:ckl7w2yd000007f103k4jdket:clo7k0sbc0001wr102fqhhris]:
                                                  Could not select input menu item: 'no input' (Jonas Mix Prep KICK 2.3: Line 68)
                                                      Could not click popup menu item
                                                      Could not find menu item with name: no input
                                                  

                                                  Now, I can live with an 88% success rate, it's just a window focusing issue after all. But I can't for the life of me understand how it can be inconsistent when all conditions and parameters are exactly the same every time. Which takes us back to the initial frustration that promted this post. I find it interesting and irritating at the same time XD

                                                  1. Chad Wahlbrink @Chad2023-10-26 19:44:49.613Z

                                                    Thanks, @Jonas_Kroon.

                                                    If you can make a screen recording of it failing, we may be able to drill down and get that success rate even higher.

                                                    The error you see usually indicates that something in your user interface (a window of some kind) is blocking Soundflow from clicking the input selector. This could happen due to the color palette opening and closing to color the track, especially if the color palette is opening overtop of your edit window's track I/O UI.

                                                    I just added a short wait on line 70 (between the color and input selection) to see if it fixes your issue: How to beat the inconsistency of scripts in SoundFlow? #post-22

                                                    If that still doesn't solve your issue, then yes, a screen recording would be best so we can see exactly what you are seeing!

                                                    Thanks for troubleshooting with us!

                                                    1. Jonas Kroon @Jonas_Kroon
                                                        2023-10-26 19:53:50.432Z

                                                        The error you see usually indicates that something in your user interface (a window of some kind) is blocking Soundflow from clicking the input selector. This could happen due to the color palette opening and closing to color the track, especially if the color palette is opening overtop of your edit window's track I/O UI.

                                                        That makes sense! I'll give it a go.

                                                    2. In reply toChad:
                                                      Jonas Kroon @Jonas_Kroon
                                                        2023-10-26 19:36:49.777Z

                                                        Hi @Chad,

                                                        I am curious if the most recent version of the script here works: How to beat the inconsistency of scripts in SoundFlow? #post-22

                                                        Yes, it works almost perfectly. I responded to it here:

                                                        With the added benefit of not needing to provide a full path to a bus, just the bus name ("Kick (Stereo)" can be found regardless of bus path, etc.

                                                        Yes, that is a nice touch for sure.

                                                        if you run into issues with the intended track selection changing on you, I'd suggest changing sf.ui.proTools.appActivateMainWindow(); to sf.ui.proTools.appActivate();

                                                        Thanks, I will definitely keep that in mind.

                                                        I also noticed that the track selection could be changed erroneously if "Link Track and Edit Selection" is off when the script is started

                                                        I'm considering creating a simple script that enables Link Track and Edit Selection that is automatically triggered anytime Pro Tools is the active application or something. As so many SF functions seem to depend on it.

                                                        Thanks again my friend.

                                                    3. In reply toJonas_Kroon:
                                                      Chad Wahlbrink @Chad2023-10-26 20:10:47.153Z2023-10-27 19:10:52.373Z

                                                      @Jonas_Kroon, one more option using some extra magic that @Kitch shared with me.

                                                      This allows you to define input, output, and color at the top, and then it will do the rest as expected. Much more re-usable overall.

                                                      Note - you mentioned that you felt like "Link Track and Edit Selection" was often required for SF functions. I removed the commands related to that in this most recent script to show that it's unnecessary for this workflow. It should work the same regardless. SF's built-in API will typically turn it on and off automatically when needed.

                                                      When you want to explore moving your tracks around, feel free to make a new post in the "How To" section of the forum, and we'll be happy to help you out! There are also many options for this workflow on the forum and the store.

                                                      
                                                      const settings = {
                                                          inputPath: "no input",
                                                          outputPaths: ["Bus 1-2 (Stereo)", "Bus 3-4 (Stereo)", "Bus 5-6 (Stereo)"],
                                                          trackColorSettings: {
                                                              colorBrightness: "Medium",
                                                              colorNumber: 10,
                                                          }
                                                      }
                                                      
                                                      /// ↑ Define your Settings Up Here ↑ ///
                                                      
                                                      function setupRestore(callback) {
                                                          // Activate Pro Tools
                                                          sf.ui.proTools.appActivate();
                                                          // Reset UI Cache
                                                          sf.ui.proTools.mainWindow.invalidate();
                                                      
                                                          if (sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isEnabled && !sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isMenuChecked) {
                                                              sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] });
                                                          }
                                                      
                                                          // Get Mix Window State
                                                          const isMixWindowActive = sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked;
                                                      
                                                          // Activate Edit Window if Mix Window is Active
                                                          if (isMixWindowActive) {
                                                              sf.ui.proTools.menuClick({ menuPath: ["Window", "Edit"], });
                                                          }
                                                      
                                                          // Try our Main Script
                                                          try {
                                                              callback();
                                                          }
                                                          catch (err) {
                                                              log(err)
                                                          }
                                                          finally {
                                                              // Restore Mix window
                                                              if (isMixWindowActive) {
                                                                  sf.ui.proTools.getMenuItem("Window", "Mix");
                                                                  sf.ui.proTools.menuClick({ menuPath: ["Window", "Mix"], });
                                                              }
                                                      
                                                              if (sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isEnabled && sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isMenuChecked) {
                                                                  sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] });
                                                              }
                                                      
                                                          }
                                                      }
                                                      
                                                      function main(settings) {
                                                          setupRestore(() => {
                                                              const currentWinPosition = sf.ui.proTools.mainWindow.position;
                                                      
                                                              // Destructure our Settings
                                                              const { inputPath, outputPaths, trackColorSettings } = settings;
                                                      
                                                              // First store the selected tracks
                                                              let selectedTracks = sf.ui.proTools.invalidate().trackGetSelectedTracks().trackHeaders.map(t => t.normalizedTrackName);
                                                      
                                                              // Select the top most track
                                                              sf.ui.proTools.trackSelectByName({ names: [selectedTracks[0]], deselectOthers: true });
                                                      
                                                              // Scroll to the top most track
                                                              sf.ui.proTools.selectedTrack.invalidate().trackScrollToView();
                                                      
                                                              // Select all of our tracks
                                                              sf.ui.proTools.trackSelectByName({ names: selectedTracks, deselectOthers: true });
                                                      
                                                              // Small Wait
                                                              sf.wait({ intervalMs: 50 });
                                                      
                                                              // Set the color of the selected tracks to settings
                                                              sf.ui.proTools.colorsSelect(trackColorSettings);
                                                      
                                                              // Error Handling - Sometimes colorSelect() will move the main window for some reason.
                                                              if (sf.ui.proTools.mainWindow.position.x !== currentWinPosition.x) {
                                                                  sf.ui.proTools.colorsSelect(trackColorSettings);
                                                                  sf.ui.proTools.mainWindow.windowMove({ position: currentWinPosition })
                                                              }
                                                      
                                                              // Set input to "no input"
                                                              sf.ui.proTools.selectedTrack.trackInputSelect({
                                                                  inputSelector: menuItems => menuItems.filter(mi => mi.path[mi.path.length - 1] === inputPath)[0],
                                                                  selectForAllSelectedTracks: true,
                                                              });
                                                      
                                                              // Set output paths defined at top of the script
                                                              outputPaths.forEach((path, i) => {
                                                                  sf.ui.proTools.selectedTrack.outputPathButton.popupMenuSelect({
                                                                      menuSelector: menuItems => menuItems.filter(mi => mi.path[mi.path.length - 1] === path)[0],
                                                                      isControl: i == 0 ? false : true,
                                                                      isShift: true,
                                                                      isOption: true,
                                                                  });
                                                              })
                                                      
                                                          });
                                                      }
                                                      
                                                      main(settings);
                                                      
                                                      1. Jonas Kroon @Jonas_Kroon
                                                          2023-10-26 20:44:33.534Z2023-10-26 20:59:07.182Z

                                                          Hey @Chad,

                                                          This last one is working very well too!

                                                          I really like that it allows you to define input, output, and color at the top.

                                                          With normal use this script succeeded 25 out of 25 times on my system.

                                                          I could force it to fail by positioning the color palette, a plug-in, or basically any floating window on top of the selected track's I/O menu. This provoked all kinds of randomness. At one point it colored all tracks in the entire session orange. I can see this becoming a problem if there are several floating windows open.

                                                          I could also force it to fail by running the script on a track that had already been targeted by the script, without re-selecting it first. In other words, repeating the script on a track without de-selecting and selecting it again. I can't see why one would use the script like this though.

                                                          Apart from that, as far as I can see, it seems stable.

                                                          1. Jonas Kroon @Jonas_Kroon
                                                              2023-10-26 20:53:32.494Z

                                                              I could force it to fail by positioning the color palette, a plug-in, or basically any floating window on top of the selected track's I/O menu

                                                              You mentioned it earlier, @Chad, and I'm starting to think that this might be the root cause of many of my problems: Floating windows covering objects that SF needs to see.

                                                              I guess an easy solution would be to open the script with a sf.ui.proTools.viewCloseFloatingWindows(); but that would be a pain in the butt for those of us who like to have loads of floating windows open.

                                                              As an example, I keep a separate screen for visual feedback like VU meters, LUFS meters, phase scope and so on. Having the script close all of them wouldn't be productive.

                                                              1. Chad Wahlbrink @Chad2023-10-26 21:29:40.348Z

                                                                Hey @Jonas_Kroon,

                                                                Yes, covering up the UI can definitely break many of the scripts and workflows possible with SoundFlow.

                                                                Here's an example of a common workaround for this issue. The script below utilizes what is called a "call back function" in JavaScript and is also roughly what was used in my previous script on this thread. This version is using

                                                                sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] }) 
                                                                

                                                                At the beginning and end of the script, we hide all of the floating windows and then show them again at the end. This way, you can leave all of your floating windows in place, and SF can do its magic without an issue.

                                                                Note, I just implemented this on the main script for this discussion here: How to beat the inconsistency of scripts in SoundFlow? #post-32

                                                                ↑ With that tweak, any plugin windows are hidden and reshown as expected.

                                                                
                                                                function setupRestore(callback) {
                                                                    // Activate Pro Tools
                                                                    sf.ui.proTools.appActivate();
                                                                    // Reset UI Cache
                                                                    sf.ui.proTools.mainWindow.invalidate();
                                                                    
                                                                    // Hide Floating Windows
                                                                    if (sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isEnabled) {
                                                                        sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] });
                                                                    }
                                                                
                                                                    // Get Mix Window State
                                                                    const isMixWindowActive = sf.ui.proTools.getMenuItem('Window', 'Mix').isMenuChecked;
                                                                
                                                                    // Activate Edit Window if Mix Window is Active
                                                                    if (isMixWindowActive) {
                                                                        sf.ui.proTools.menuClick({ menuPath: ["Window", "Edit"], });
                                                                    }
                                                                
                                                                    // Try our Main Script
                                                                    try {
                                                                        callback();
                                                                    }
                                                                    catch (err) {
                                                                        log(err)
                                                                    }
                                                                    finally {
                                                                        // Restore Mix window
                                                                        if (isMixWindowActive) {
                                                                            sf.ui.proTools.getMenuItem("Window", "Mix");
                                                                            sf.ui.proTools.menuClick({ menuPath: ["Window", "Mix"], });
                                                                        }
                                                                        // Restore Floating windows
                                                                        if (sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isMenuChecked) {
                                                                            sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] });
                                                                        }
                                                                
                                                                    }
                                                                }
                                                                
                                                                function main() {
                                                                    setupRestore(() => {
                                                                
                                                                        // place your main actions in here! 
                                                                        alert('everything is hidden and we are doing work');
                                                                        
                                                                    });
                                                                }
                                                                
                                                                main();
                                                                
                                                                

                                                                Andrew Scheps also has a package on the store that helps maintain complex screen layouts with Window Configurations.

                                                                ReplySolution
                                                                1. Jonas Kroon @Jonas_Kroon
                                                                    2023-10-26 21:45:54.560Z

                                                                    Ooh, that is sweet!

                                                                    With that last little tweak hiding all floating windows the script succeeds 25 out of 25 times on my system, and I can't make it break.

                                                                    Well, there is still the error I mentioned that's happening when I select a bunch of tracks, run the script on them and then immediately run it again afterwards. But that's not how I'm going to use the script so I'm not going to worry about that.

                                                                    Thanks again @Chad, you're a wizard!

                                                                    I will definitely check out Andrew Scheps' trickery too.

                                                                    1. In reply toChad:
                                                                      Jonas Kroon @Jonas_Kroon
                                                                        2023-10-27 18:46:14.836Z

                                                                        Quick question, @Chad, if you don't mind:

                                                                        In this version of the script, how would I route a track to multiple buses?

                                                                        In my original script I did it like this:

                                                                        sf.ui.proTools.selectedTrack.outputPathButton.popupMenuSelect({
                                                                                menuPath: ["bus", "bus menu 1-128", "Bass Lo (Stereo)"]
                                                                            });
                                                                        
                                                                        sf.ui.proTools.selectedTrack.outputPathButton.popupMenuSelect({
                                                                                isControl: true,
                                                                                menuPath: ["bus", "bus menu 1-128", "Bass Hi (Stereo)"]
                                                                            });
                                                                        
                                                                        sf.ui.proTools.selectedTrack.outputPathButton.popupMenuSelect({
                                                                                isControl: true,
                                                                                menuPath: ["bus", "bus menu 1-128", "Bass Parallel (Stereo)"]
                                                                            });
                                                                        

                                                                        I can't seem to grasp how to implement it in this version of the script though.

                                                                        1. Chad Wahlbrink @Chad2023-10-27 19:15:03.852Z

                                                                          Hey @Jonas_Kroon,

                                                                          I tweaked the last script again:

                                                                          I made the outputPaths setting at the top into an array. So you would set that to:

                                                                          const settings = {
                                                                              inputPath: "no input",
                                                                              outputPaths: ["Bass Lo (Stereo)", "Bass Hi (Stereo)", "Bass Hi (Stereo)"],
                                                                              trackColorSettings: {
                                                                                  colorBrightness: "Medium",
                                                                                  colorNumber: 10,
                                                                              }
                                                                            }
                                                                          }
                                                                          

                                                                          Then, that array is iterated on later in the script:

                                                                           outputPaths.forEach((path, i) => {
                                                                                      sf.ui.proTools.selectedTrack.outputPathButton.popupMenuSelect({
                                                                                          menuSelector: menuItems => menuItems.filter(mi => mi.path[mi.path.length - 1] === path)[0],
                                                                                          isControl: i == 0 ? false : true,
                                                                                          isShift: true,
                                                                                          isOption: true,
                                                                                      });
                                                                                  })
                                                                          
                                                                          1. Jonas Kroon @Jonas_Kroon
                                                                              2023-10-28 07:48:55.247Z

                                                                              Thank you, it works perfectly!