No internet connection
  1. Home
  2. How to

How to adapt this code to selected tracks

By Steve Bissinger @sbiss2022-01-29 15:17:18.013Z2022-01-29 23:07:34.423Z

I'd like to adapt this code to effect the selected tracks rather than just a single track. Currently if I select more than one track it only does it to the 1st selected track. Tried changing selectedTrack to selectedTracks, but am getting an error...

sf.ui.proTools.selectedTrack.trackDisplaySelect({
    displayPath: ['pan', 'front pos']
    onError: 'Continue',

});

sf.ui.proTools.selectedTrack.trackDisplaySelect({
    displayPath: ['pan left', 'front pos left']
    onError: 'Continue',
});

var size = 'large';

var f = sf.ui.proTools.selectedTrack.frame;
var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
    relativePosition: { x: f.w - 10, y: 5 },
    isOption: true,
    isShift: true,
}).popupMenu;

popupMenu.menuClickPopupMenu({
    menuPath: [size]
});

sf.keyboard.press({ keys: "alt + f", });
  • 9 replies
  1. samuel henriques @samuel_henriques
      2022-01-29 20:47:59.941Z

      Hello Steve,

      Add your code here, hope it helps:

      function action() {
      
      /// Code to repeat on every selected track goes here.
      
      
      
      }
      
      
      //Get selected tracks
      const originalTracks = sf.ui.proTools.selectedTrackNames;
      
      //Do for each track.
      sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
      
          //Select track
          track.trackSelect();
      
          //Scroll track into View
          track.trackScrollToView();
      
          action()
      });
      
      //Restore previously selected tracks
      sf.ui.proTools.trackSelectByName({ names: originalTracks });
      
      1. Thank you Samuel!

        This works, but is a little slow. What I was hoping to simulate is if I had multiple tracks selected and held down opt-shift while selecting the pan lane. That method changes all the track views to that lane at the same time, rather than track by track. Is it possible to just add those modifiers to my original script? Or another way to achieve that?

        1. samuel henriques @samuel_henriques
            2022-01-30 11:05:34.948Z

            Yes, it's possible,

            sf.ui.proTools.selectedTrack.trackDisplaySelect({
                displayPath: ['pan', 'front pos'],
                selectForAllSelectedTracks: true,
            });
            

            To find these extra properties, just press F2, and you'll get a list like this.

            1. Thanks so much for your help Samuel. This works perfectly! You made me realize that my global trigger F2 (launch Pro Tools) is overriding that function in SF.

          • AAlex Oldroyd @Alex_Oldroyd8
              2022-04-11 12:27:14.855Z

              Hi @samuel_henriques I'm struggling to adapt this script to work with Logic pro X. do you have any idea how to do so?

              1. samuel henriques @samuel_henriques
                  2022-06-10 17:49:27.034Z

                  Hello Alex,

                  I don't have Logic at the moment so won't be able to help there.
                  But if you were to do it on pro tools it would be like so:

                  sf.ui.proTools.appActivateMainWindow();
                  
                  sf.ui.proTools.invalidate();
                  
                  //Get selected tracks
                  const originalTracks = sf.ui.proTools.selectedTrackNames;
                  
                  //Do for each track.
                  sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
                  
                      //Select track
                      track.trackSelect();
                  
                      //Scroll track into View
                      track.trackScrollToView();
                  
                      //Code to execute here
                  
                  
                  });
                  
                  //Restore previously selected tracks
                  sf.ui.proTools.trackSelectByName({ names: originalTracks });
                  

                  Hope this helps you adapt for Logic.

              2. In reply tosbiss:
                Kitch Membery @Kitch2022-01-29 23:07:19.645Z

                Hi Steve,

                Please check this tutorial for how to quote code in the SoundFlow forum, so that it displays in a readable format:

                Rock on!

                1. I watched it...apologies that after all these years I was still doing it wrong! My questions will be beautifully formatted from now on!

                  1. Kitch Membery @Kitch2022-01-30 03:22:49.661Z

                    Hahahahahah No worries legend :-)