No internet connection
  1. Home
  2. How to

Toggle "Output window Follow selected track" On or Off

By Nicolas Bourgeois @Nicolas_Bourgeois
    2025-04-11 18:13:04.952Z

    Hello
    I've been arround the forum and read many post about this but I don't really find what I want to do :

    A single button on my stream deck wich would toggle enable and disable "Output window Follow selected track"
    Easy to add the script as first action in a toggle macro to enable but what to put in the second action to disable ?

    Also I'd like the script to not be running in the background anymore while toggled off

    Thanks

    Nico

    Solved in post #3, click to view
    • 5 replies
    1. Chad Wahlbrink @Chad
        2025-04-11 18:52:28.967Z2025-04-11 21:10:29.006Z

        Hi, @Nicolas_Bourgeois,

        I have been meaning to implement this for a while. This will start and stop the script by running the script more than once:

        let lastFocusedTrackName;
        
        function main() {
            try {
                let newName = sf.ui.proTools.selectedTrack.normalizedTrackName;
                if (newName === lastFocusedTrackName || newName === undefined) return;
        
                lastFocusedTrackName = newName;
        
                // If An Output Window Exists and An Output Window is open
                if (sf.ui.proTools.mainTrackOutputWindow.exists && sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value !== 'open')
                    sf.ui.proTools.selectedTrack.trackOutputToggleShow({ onError: 'Continue' });
        
            } catch (err) {
            }
        }
        
        function runForever(name, action, interval) {
            // If globalState is defined, then stop the loop 
            if (globalState[name]) {
                log(name + " is Stopping");
                globalState[name] = null;
                return;
            }
        
            // Start the loop
            log(name + " is Starting");
            globalState[name] = true;
        
            sf.engine.runInBackground(function () {
                try {
                    // Keep looping while this named loop is still active
                    while (globalState[name] && sf.ui.proTools.isRunning) {
                        sf.engine.checkForCancellation();
        
                        action();
        
                        sf.wait({ intervalMs: interval, executionMode: 'Background' });
                    }
                }
                finally {
                    globalState[name] = null;
                }
            });
        }
        
        runForever("Output Window: Follow Selected Track", main, 500);
        
        1. O
          ReplySolution
          1. N
            Nicolas Bourgeois @Nicolas_Bourgeois
              2025-04-13 16:23:04.057Z

              Thanks guys :) that's exactly what I need

              1. N
                Nicolas Bourgeois @Nicolas_Bourgeois
                  2025-04-13 16:26:51.246Z

                  just a question @Owen_Granich_Young
                  I've tried the script in the post you mentioned.
                  I've put this script on a streamdeck key as a toggle.
                  Does the script still run in background while "disabled" or is it "kill" and relaunch when relaunched ?
                  Meaning does it takes ressources while disabled ?

                  Thanks

                  1. Chad Wahlbrink @Chad
                      2025-04-13 19:38:01.236Z

                      Both Owen’s script and the script shared above will exit the while loop once it runs a second time - so no more resources will be used after that.

                      The Global State variable will remain stored in memory until SoundFlow is restarted, but it won’t be using any resources.