No internet connection
  1. Home
  2. How to

Application trigger toggle on off

By Emil Isaksson @studiomollan
    2020-02-21 19:30:06.937Z

    Is there a way to add a button on my stream deck to turn the application trigger of a shortcut on/off.
    I'm thinking of the "Output window follow selection" command. That can't have a standard trigger as it needs to allways be on or off.

    Solved in post #9, click to view
    • 12 replies
    1. Hi Emil.

      Right now there's no function in SoundFlow to control the enabled state of other triggers, but we will likely add that some time in the future.

      For now what you need is to use a globalState variable to toggle whether or not that other script should work or not. So you'll have two scripts, one that toggles the "on/off state" but it saves this info in a global state variable, that is then read by the "Output window follow selection" script (which will need to be modified).

      1. Which of the Output window follow selection scripts are you using? One from the forum or from my package?
        If you share the script here I can help you add the needed code.

      2. S
        In reply tostudiomollan:
        Emil Isaksson @studiomollan
          2020-02-23 22:54:42.288Z

          Hi!
          It's from the "pro tools utilities 10.0.17" Not sure thats one of yours or the forum. Think the later.
          Heres the script.

          1. Can you copy/paste the script so I don't have to rewrite it line by line?

            1. SEmil Isaksson @studiomollan
                2020-02-23 23:02:40.486Z2020-02-23 23:04:35.336Z
                var lastFocusedTrackName;
                
                function main() {
                    try {
                
                        var newName = sf.ui.proTools.selectedTrackNames[0];
                        if (newName === lastFocusedTrackName || newName === undefined) return;
                
                        lastFocusedTrackName = newName;
                
                        if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value !== 'open')
                            sf.ui.proTools.selectedTrack.trackOutputToggleShow({ onError: 'Continue' });
                
                    } catch (err) {
                    }
                }
                
                function runForever(name, action, interval, timeout) {
                    var now = (new Date).valueOf();
                    if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
                
                    globalState[name] = now;
                    sf.engine.runInBackground(function () {
                        try {
                            while (true) {
                                sf.engine.checkForCancellation();
                                globalState[name] = (new Date).valueOf();
                
                                action();
                
                                sf.wait({ intervalMs: interval, executionMode: 'Background' });
                            }
                        } finally {
                            globalState[name] = null;
                        }
                    });
                }
                
                runForever("isFollowFocusedTrackRunning", main, 500, 5000);
                
                1. Okay. Create a new script and use this instead (ie. remove triggers to the existing script and move them over to this new one):

                  var lastFocusedTrackName;
                  
                  function main() {
                      try {
                  
                          var newName = sf.ui.proTools.selectedTrackNames[0];
                          if (newName === lastFocusedTrackName || newName === undefined) return;
                  
                          lastFocusedTrackName = newName;
                  
                          if (!globalState.isFollowFocusedTrackActive) return;
                          
                          if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value !== 'open')
                              sf.ui.proTools.selectedTrack.trackOutputToggleShow({ onError: 'Continue' });
                  
                      } catch (err) {
                      }
                  }
                  
                  function runForever(name, action, interval, timeout) {
                      var now = (new Date).valueOf();
                      if (now - globalState[name] < timeout) throw 0; //Exit if we were invoked again inside the timeout
                  
                      globalState[name] = now;
                      sf.engine.runInBackground(function () {
                          try {
                              while (true) {
                                  sf.engine.checkForCancellation();
                                  globalState[name] = (new Date).valueOf();
                  
                                  action();
                  
                                  sf.wait({ intervalMs: interval, executionMode: 'Background' });
                              }
                          } finally {
                              globalState[name] = null;
                          }
                      });
                  }
                  
                  runForever("isFollowFocusedTrackRunning", main, 500, 5000);
                  

                  Now, create yet one more script that you call "Toggle Follow Focused Track" and put this code in there:

                  globalState.isFollowFocusedTrackActive = !globalState.isFollowFocusedTrackActive;
                  
                  log(`Follow Focused Track is now: ${globalState.isFollowFocusedTrackActive ? 'ON' : 'OFF'}`);
                  

                  This 2nd script toggles whether or not the 1st script should do the following or not.

                  Reply1 LikeSolution
            2. S
              In reply tostudiomollan:
              Emil Isaksson @studiomollan
                2020-02-23 23:03:15.332Z

                It just looks weird when i do it.

                1. I've edited your post now. You can format code in the forum by having three back ticks on a separate line before and after the code: ```
                  To see it for yourself, try editing your post, you can see how I formatted yours.

                2. S
                  In reply tostudiomollan:
                  Emil Isaksson @studiomollan
                    2020-02-23 23:12:36.721Z

                    Cool! Thanks!

                    1. SEmil Isaksson @studiomollan
                        2020-02-23 23:22:30.660Z

                        Too late to try this out now but I'll get to to it by tomorrow.
                        Thank you Christian!

                      • S
                        In reply tostudiomollan:
                        Emil Isaksson @studiomollan
                          2020-02-24 12:20:31.665Z

                          Works Great!!! Exactly what i wanted!

                          1. Awesome!