No internet connection
  1. Home
  2. How to

Turn selected track down -15 dB

By Ryan Short @Ryan_Short
    2021-05-07 18:50:16.028Z

    Hi all,

    I recently found a script from Andrew Scheps in another thread that would turn down the volume of a track in pro tools the assigned amount. And it works perfectly for the assigned track in the script, but I'd love the script to be more general and work for whichever track I have selected, regardless of its name. I imagine there is a relatively simple way to adjust this code to make it work, I just have no clue how to do it myself. Thanks for your help!!

    Here is the original script I have so far:

    const TARGET_TRACK = "Audio 7";
    const VOLUME = '-15';
    sf.ui.proTools.appActivateMainWindow();
    const checkBoxes = [
    { Title: 'I/O', State: "Enable" },

    ];
    function setCheckboxState(item) {
    sf.ui.proTools.menuClick({
    menuPath: ['View', 'Edit Window Views', item.Title],
    targetValue: item.State,
    onError: "Continue",
    })
    }
    function setupScreen() {
    //Make sure I/O visible in Edit window
    checkBoxes.forEach(setCheckboxState);
    }

    function setVolume() {
    sf.ui.proTools.mainWindow.invalidate();
    if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open')
    sf.ui.proTools.selectedTrack.outputWindowButton.elementClick();

    var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) {
        return w.children.whoseTitle.is('Volume').exists;
    })[0];
    
    win.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
    sf.keyboard.type({ text: VOLUME });
    sf.keyboard.press({ keys: 'enter' });
    

    }

    function main() {
    setupScreen();
    //Save the name of the originally selected track

    var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
    
    //Select the desired track
    sf.ui.proTools.trackSelectByName({ names: [TARGET_TRACK] });
    
    //Set the volume
    setVolume();
    
    
    //Select original track again
    sf.ui.proTools.trackSelectByName({ names: [originalTrackName] });
    

    }

    main();

    • 8 replies
    1. Chris Shaw @Chris_Shaw2021-05-08 00:14:23.602Z2021-05-08 00:28:05.379Z

      You were pretty close.

      This will set all selected tracks to -15. To set another volume just change VOLUME = to the desired value.

      const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames;
      const VOLUME = '-15';
      sf.ui.proTools.appActivateMainWindow();
      const checkBoxes = [
          { Title: 'I/O', State: "Enable" },
      
      ];
      function setCheckboxState(item) {
          sf.ui.proTools.menuClick({
              menuPath: ['View', 'Edit Window Views', item.Title],
              targetValue: item.State,
              onError: "Continue",
          })
      }
      function setupScreen() {
          //Make sure I/O visible in Edit window
          checkBoxes.forEach(setCheckboxState);
      }
      
      function setVolume() {
          sf.ui.proTools.mainWindow.invalidate();
          if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open')
              sf.ui.proTools.selectedTrack.outputWindowButton.elementClick();
      
          var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) {
              return w.children.whoseTitle.is('Volume').exists;
          })[0];
      
          win.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
          sf.keyboard.type({ text: VOLUME });
          sf.keyboard.press({ keys: 'enter' });
      }
      
      function main() {
          setupScreen();
          for (var i = 0; i < TARGET_TRACKS.length; i++) {
              //Select the desired track
              sf.ui.proTools.trackSelectByName({ names: [TARGET_TRACKS[i]] });
      
              //Set the volume
              setVolume();
          };
      
          //Select original track again
          sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS });
      }
      
      main();
      

      PS - when you have a minute check this video out to learn how to post code on the forum:
      How to quote code in the SoundFlow forum.

      1. RRyan Short @Ryan_Short
          2021-05-08 00:27:12.178Z

          Ah lovely, this is great, thanks so much Chris! Last little help request: would it be possible to also add that it then closes the fader window when the function is complete? (Sorry, I intend to learn how to do this stuff myself!)

          And yes, I'm definitely gonna check out this link you sent, thanks for the help!

          1. No problem. I've even shortened the code by replacing the the for loop with a forEach loop:

            const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames;
            const VOLUME = '-15';
            sf.ui.proTools.appActivateMainWindow();
            const checkBoxes = [
                { Title: 'I/O', State: "Enable" },
            
            ];
            function setCheckboxState(item) {
                sf.ui.proTools.menuClick({
                    menuPath: ['View', 'Edit Window Views', item.Title],
                    targetValue: item.State,
                    onError: "Continue",
                })
            }
            function setupScreen() {
                //Make sure I/O visible in Edit window
                checkBoxes.forEach(setCheckboxState);
            }
            
            function setVolume() {
                sf.ui.proTools.mainWindow.invalidate();
                if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open')
                    sf.ui.proTools.selectedTrack.outputWindowButton.elementClick();
            
                var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) {
                    return w.children.whoseTitle.is('Volume').exists;
                })[0];
            
                win.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
                sf.keyboard.type({ text: VOLUME });
                sf.keyboard.press({ keys: 'enter' });
            }
            
            function main() {
                setupScreen();
            
                TARGET_TRACKS.forEach(function (track) {
                    sf.ui.proTools.trackSelectByName({ names: [track] });
            
                    //Set the volume
                    setVolume();
                });
            
                //Select original track(s) again
                sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS });
            }
            
            main();
            
            sf.ui.proTools.mainTrackOutputWindow.getElement("AXCloseButton").elementClick();
            
            1. RRyan Short @Ryan_Short
                2021-05-08 00:37:55.336Z

                Oh man, amazing! Works perfectly, thank so much! This is so helpful for when I drag in samples or something into my session and instantly need to just knock them down a bit to fit with the rest of my gain structure! Thanks Chris!

                1. In reply toChris_Shaw:
                  MMarc Bazerman @Marc_Bazerman
                    2022-01-04 23:03:26.056Z

                    This is great, building this into a bigger script that I am creating for important of tracks.
                    Thanks

              • M
                In reply toRyan_Short:
                Matthew Bronleewe @Matthew_Bronleewe
                  2024-02-02 21:18:33.212Z

                  Is there a way to have this script ask what volume you want to set to?

                  1. Nathan Salefski @nathansalefski
                      2024-02-02 22:10:01.373Z2024-02-02 23:53:03.056Z

                      Sure is, you would just need to change the constant variable of VOLUME to a prompt like below:

                      const TARGET_TRACKS = sf.ui.proTools.selectedTrackNames;
                      
                      const VOLUME = sf.interaction.displayDialog({
                          prompt: `Enter Target Volume`,
                          defaultAnswer: '',
                          buttons: ['Cancel', 'OK'],
                          defaultButton: 'OK',
                      }).text;
                      
                      sf.ui.proTools.appActivateMainWindow();
                      
                      const checkBoxes = [
                          { Title: 'I/O', State: "Enable" },
                      ];
                      
                      function setCheckboxState(item) {
                          sf.ui.proTools.menuClick({
                              menuPath: ['View', 'Edit Window Views', item.Title],
                              targetValue: item.State,
                              onError: "Continue",
                          })
                      }
                      
                      function setupScreen() {
                          //Make sure I/O visible in Edit window
                          checkBoxes.forEach(setCheckboxState);
                      }
                      
                      function setVolume() {
                          sf.ui.proTools.mainWindow.invalidate();
                          if (sf.ui.proTools.selectedTrack.outputWindowButton.value.invalidate().value != 'open')
                              sf.ui.proTools.selectedTrack.outputWindowButton.elementClick();
                      
                          var win = sf.ui.proTools.floatingWindows.allItems.filter(function (w) {
                              return w.children.whoseTitle.is('Volume').exists;
                          })[0];
                      
                          win.textFields.whoseTitle.is('Volume Numerical').first.elementClick();
                          sf.keyboard.type({ text: VOLUME });
                          sf.keyboard.press({ keys: 'enter' });
                      }
                      
                      function main() {
                          setupScreen();
                      
                          TARGET_TRACKS.forEach(function (track) {
                              sf.ui.proTools.trackSelectByName({ names: [track] });
                      
                              //Set the volume
                              setVolume();
                          });
                      
                          //Select original track(s) again
                          sf.ui.proTools.trackSelectByName({ names: TARGET_TRACKS });
                      }
                      
                      main();
                      
                      sf.ui.proTools.mainTrackOutputWindow.getElement("AXCloseButton").elementClick();
                      
                    • M
                      In reply toRyan_Short:
                      Matthew Bronleewe @Matthew_Bronleewe
                        2024-02-02 22:37:51.461Z

                        For some reason I got an error the first time it ran, but now it's running smoothly! This is great, thanks!