No internet connection
  1. Home
  2. How to

Any idea how to select all empty tracks in a session?

By Davide Favargiotti @dieffe
    2018-09-06 11:17:53.218Z

    Didn't really have any time to think about it, but I was wondering if anybody already made a script that does that...
    In a middle of a project where I have to move things a LOT between sessions and I want to delete all the empty tracks while selecting what I need to move, so have less track to import.
    Cheers

    Solved in post #17, click to view
    • 23 replies

    There are 23 replies. Estimated reading time: 19 minutes

    1. Something like this could work. For this to work all tracks (that you want to operate on) need to be visible, and you need to manually select the first track before starting the script.

      sf.ui.proTools.appActivateMainWindow();
      
      var lastSelectedName;
      
      function selectNextTrack()
      {
          //Select next track
          sf.keyboard.press({ keys: 'semicolon' });
      
          //Make sure we changed tracks (we're not on last track)
          var newName = sf.ui.proTools.selectedTrackNames[0];
          if (newName === lastSelectedName)
              return false;
          lastSelectedName = newName;
          return true;
      }
      
      //Repeat for each track until someone breaks the loop
      while(true)
      {
          var mi = sf.ui.proTools.getMenuItem('Track', 'Delete');
          if (mi.exists)
          {
              //If this menu item exists it means the track is empty
              mi.elementClick();
          }
      
          if (!selectNextTrack())
              break; //we're out of tracks, break the while loop
      }
      
      
      1. Oops also forgot to say. This script doesn't select all empty tracks. It deletes them; that was easier to implement.

        1. DDavide Favargiotti @dieffe
            2018-09-09 21:04:41.756Z

            I tried this one, very cool. Don't understand exactly the code, but is's interesting.
            The issue I found is that this script, once it deletes a track, it starts over from the first track to check if the track is empty: e.g. after deleting the 21st track in the session, the selection goes back to track one and check again each and every track.

            Shouldn't it be better if the script kept in memory two tracks names, the current one and the previous one, so that once it check the new one with the current one, and deletes it because it's empty, we can recap the previous previous track name and start checking the tracks from that one?

        2. In reply todieffe:

          @dieffe also looking forward to seeing some of your own scripts in a package soon :) I'm sure you have a good collection. Please let me know if there's anything holding you back from being able to share.

          1. DDavide Favargiotti @dieffe
              2018-09-08 07:11:13.438Z

              Thank you Christian, I’ll have a look later when I get to my studio.

              The only reason I didn’t share anything yet is because I have yet to upgrade to the latest beta :) busy week editing, didn’t want to risk breaking any workflow as I have to work on a lot of dialogue.

              And I think I will need some time to comment my scripts... especially to make clear when the script is working and when it breaks completely :) My scripts are mostly reckless macro tailor made on my workflow and don’t have a lot of safety nets.
              If I have some time this weekend I’ll upgrade to the new beta

              1. Yay sounds great. Thank you @dieffe for the update. Let's keep in touch about how to collaborate on scripts etc. I'd love to give you feedback/reviews on your scripts as a help to make them more safe etc. Maybe that could help speed up the process :)

                1. DDavide Favargiotti @dieffe
                    2018-09-08 12:33:38.873Z

                    Definitely, thank you!
                    And BTW this triggers one question: is it possible to share a package only to a specific user?
                    Eg to you just for testing purposes or to my team members? Is his something you're planning to implement?

              2. In reply todieffe:
                Chris Atkins @iamchrisatkins
                  2019-01-22 07:32:11.373Z

                  Hey! This is cool, but it deletes the AUX tracks! It also takes quite a lot of time :-)

                  1. V
                    In reply todieffe:
                    Vanessa Garde @Vanessa_Garde
                      2019-10-18 05:43:12.829Z

                      Hi there,

                      Thanks for the script, Christian.

                      Would it be possible to do this:

                      • On Audio Tracks Only,
                      • that are part of a selection, not the entire session?
                      • In stead of delete, hide and make inactive?

                      I am working on some pretty track heavy sessions and have to go and find all empty audio tracks that don't contain anything, and then hide and make inactive manually. This would tremendly help!

                      Thanks!

                      Vanessa G.

                      1. Hi @Vanessa_Garde

                        Yes certainly :) This script should do that:

                        sf.ui.proTools.appActivateMainWindow();
                        
                        function processTrack(trackName) {
                            sf.ui.proTools.trackSelectByName({ names: [trackName], deselectOthers: true });
                            if (sf.ui.proTools.selectedTrackNames[0] !== trackName)
                                throw 'Could not select track: ' + trackName;
                        
                            //Refresh menu
                            sf.ui.proTools.selectedTrack.trackScrollToView();
                            sf.ui.proTools.selectedTrack.titleButton.mouseClickElement();
                        
                            var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
                            var trackIsAudioTrack = sf.ui.proTools.selectedTrack.title.value.indexOf('Audio Track') >= 0;
                        
                            if (trackIsEmpty && trackIsAudioTrack) {
                                sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({
                                    isRightClick: true,
                                    menuPath: ['Hide and Make Inactive'],
                                });
                            }
                        }
                        
                        function main() {
                            var trackNames = sf.ui.proTools.selectedTrackNames.slice();
                            trackNames.map(processTrack);
                        }
                        
                        main();
                        
                        1. SSimon Franglen @Simon_Franglen
                            2020-03-19 22:31:32.311Z2020-03-19 22:32:49.718Z

                            Hi Christian,
                            I'm trying to adapt these scripts to Instrument and Midi tracks. It seems like the variable 'Instrument Track' doesn't exist, or at least, I can't get it to work on a small session with mixed Audio, Instrument and Midi Tracks.
                            In a perfect world, I'd have a single script that selected both empty Instrument and Midi tracks, ready for deletion. In our mega-huge instrument templates (500+ tracks) it would be immensely useful when passing these on.

                            Here's what I tried so far:

                            sf.ui.proTools.appActivateMainWindow();
                            
                            function isTrackEmptyInstrumentTrack(trackName) {
                                sf.ui.proTools.trackSelectByName({ names: [trackName], deselectOthers: true });
                                if (sf.ui.proTools.selectedTrackNames[0] !== trackName)
                                    throw 'Could not select track: ' + trackName;
                            
                                //Refresh menu
                                sf.ui.proTools.selectedTrack.trackScrollToView();
                                sf.ui.proTools.selectedTrack.titleButton.mouseClickElement();
                            
                                var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
                                var trackIsInstrumentTrack = sf.ui.proTools.selectedTrack.title.value.indexOf('Instrument Track') >= 0;
                            
                                return trackIsEmpty && trackIsInstrumentTrack;
                            }
                            
                            function main() {
                                var originalTrackNames = sf.ui.proTools.trackNames.slice();
                                var trackNamesToSelect = originalTrackNames.filter(isTrackEmptyInstrumentTrack);
                            
                                sf.ui.proTools.trackSelectByName({
                                    names: trackNamesToSelect,
                                    deselectOthers: true,
                                });
                            }
                            
                            main();
                            
                            1. Hi Simon.

                              Try this - this version selects all empty MIDI and Instrument tracks (and is a lot faster than the original script):

                              sf.ui.proTools.appActivateMainWindow();
                              
                              function isTrackEmptyInstrumentOrMIDITrack(trackName) {
                                  sf.ui.proTools.trackSelectByName({ names: [trackName], deselectOthers: true, });
                                  if (sf.ui.proTools.selectedTrackNames[0] !== trackName)
                                      throw 'Could not select track: ' + trackName;
                              
                                  //Refresh menu
                                  sf.keyboard.press({ keys: 'down' });
                              
                                  var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
                                  var trackIsInstrumentTrack = sf.ui.proTools.selectedTrack.title.value.indexOf('Inst Track') >= 0;
                                  var trackIsMIDITrack = sf.ui.proTools.selectedTrack.title.value.indexOf('MIDI Track') >= 0;
                              
                                  return trackIsEmpty && (trackIsInstrumentTrack || trackIsMIDITrack);
                              }
                              
                              function ensureSettings() {
                                  //Ensure Link Track and Edit Selection is turned on
                                  if (sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.value.invalidate().value !== "Selected")
                                      sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.elementClick();
                              }
                              
                              function main() {
                                  ensureSettings();
                              
                                  var originalTrackNames = sf.ui.proTools.trackNames.slice();
                                  var trackNamesToSelect = originalTrackNames.filter(isTrackEmptyInstrumentOrMIDITrack);
                              
                                  sf.ui.proTools.trackSelectByName({
                                      names: trackNamesToSelect,
                                      deselectOthers: true,
                                  });
                              }
                              
                              main();
                              
                              1. SSimon Franglen @Simon_Franglen
                                  2020-03-20 13:30:39.397Z2020-03-20 13:38:39.358Z

                                  That's brilliant.
                                  Just tested this with a session with 600 mixed empty/full audio/midi/instrument tracks. It took about 4 minutes to select all the empty midi/audio

                                  This will save me days

                                  ADDENDUM: It looks as though the graphics in Pro Tools are incorrectly. The actual tracks are selected correctly, but the show/hide seems to show errors.

                                  Addendum 2: I spoke too soon. Later on in the scan there are errors, empty tracks are being selected as well as full ones.

                                  Here's the session (no plugins needed) if you want to test it.

                                  https://www.dropbox.com/s/wliggwkf0j6rmg9/Test%20empty%20full.ptx?dl=0
                                  1. SSimon Franglen @Simon_Franglen
                                      2020-03-20 13:41:44.320Z

                                      Also two other problems.

                                      1: Can I define a selection of tracks
                                      2: If I show only a selection of tracks, it doesn't stop with only the shown tracks, it then continues through all tracks in the session

                                      1. You can change this line:

                                        var originalTrackNames = sf.ui.proTools.trackNames.slice();
                                        

                                        to

                                        var originalTrackNames = sf.ui.proTools.visibleTrackNames.slice();
                                        

                                        for it to only work on the visible tracks - and I think you can use selectedTrackNames to start at the selected tracks.

                                        1. Try this - it has some improvements and only works on the visible tracks:

                                          sf.ui.proTools.appActivateMainWindow();
                                          
                                          function isTrackEmptyInstrumentOrMIDITrack(trackName) {
                                              var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
                                              var trackIsInstrumentTrack = track.title.value.indexOf('Inst Track') >= 0;
                                              var trackIsMIDITrack = track.title.value.indexOf('MIDI Track') >= 0;
                                              if (!(trackIsInstrumentTrack || trackIsMIDITrack)) return false;
                                          
                                              track.trackSelect();
                                              if (sf.ui.proTools.selectedTrackNames[0] !== trackName)
                                                  throw 'Could not select track: ' + trackName;
                                          
                                              //Refresh menu
                                              sf.keyboard.press({ keys: 'comma, period' });
                                          
                                              var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
                                              return trackIsEmpty;
                                          }
                                          
                                          function ensureSettings() {
                                              //Ensure Link Track and Edit Selection is turned on
                                              if (sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.value.invalidate().value !== "Selected")
                                                  sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.elementClick();
                                          }
                                          
                                          function main() {
                                              ensureSettings();
                                          
                                              var originalTrackNames = sf.ui.proTools.visibleTrackNames.slice();
                                              var trackNamesToSelect = originalTrackNames.filter(isTrackEmptyInstrumentOrMIDITrack);
                                          
                                              sf.ui.proTools.trackSelectByName({
                                                  names: trackNamesToSelect,
                                                  deselectOthers: true,
                                              });
                                          
                                              sf.keyboard.press({ keys: 'comma, period' });
                                          }
                                          
                                          main();
                                          

                                          When it's done you may have to cmd+click one selected track to make sure the "Track -> Delete" menu is updated. If it has no "..." after Delete you know that it succeeded.

                                          ReplySolution
                                          1. SSimon Franglen @Simon_Franglen
                                              2020-03-20 14:10:23.209Z

                                              That's working here. The delete seems to reflect the tracks correctly. awesome

                              2. S
                                In reply todieffe:
                                Simon Franglen @Simon_Franglen
                                  2020-03-20 14:23:36.115Z2020-03-20 23:01:39.518Z

                                  I tweaked it for audio tracks selection as well

                                  sf.ui.proTools.appActivateMainWindow();
                                  
                                  function isTrackEmptyAudioTrack(trackName) {
                                      var track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
                                      var trackIsAudioTrack = track.title.value.indexOf('Audio Track') >= 0;
                                  
                                      if (!(trackIsAudioTrack)) return false;
                                  
                                      track.trackSelect();
                                      if (sf.ui.proTools.selectedTrackNames[0] !== trackName)
                                          throw 'Could not select track: ' + trackName;
                                  
                                      //Refresh menu
                                      sf.keyboard.press({ keys: 'comma, period' });
                                  
                                      var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
                                      return trackIsEmpty;
                                  }
                                  
                                  function ensureSettings() {
                                      //Ensure Link Track and Edit Selection is turned on
                                      if (sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.value.invalidate().value !== "Selected")
                                          sf.ui.proTools.mainWindow.cursorToolCluster.linkTrackAndEditSelectionButton.elementClick();
                                  }
                                  
                                  function main() {
                                      ensureSettings();
                                  
                                      var originalTrackNames = sf.ui.proTools.visibleTrackNames.slice();
                                      var trackNamesToSelect = originalTrackNames.filter(isTrackEmptyAudioTrack);
                                  
                                      sf.ui.proTools.trackSelectByName({
                                          names: trackNamesToSelect,
                                          deselectOthers: true,
                                      });
                                  
                                      sf.keyboard.press({ keys: 'comma, period' });
                                  }
                                  
                                  main();
                                  
                                  1. S
                                    In reply todieffe:
                                    Sean McDonald @Sean_McDonald5
                                      2024-08-28 04:35:08.292Z

                                      Hello All,
                                      Im getting a SF error:
                                      "delete empty tracks failed
                                      referenceerror reply not defined
                                      (DELETE EMPTY TRACLS line 41)

                                      any idea what I might be doing incorrectly?

                                      thanks for your time

                                      1. Hi Sean,

                                        That sounds like a copy/paste error. There's none of the code in this page that contains an identifier "reply" - but there's a reply button after each post, so you may have accidentally included that in your copy.

                                        1. SSean McDonald @Sean_McDonald5
                                            2024-08-28 16:36:35.081Z

                                            Thank you.

                                            We will, re-copy and re-paste

                                        2. S
                                          In reply todieffe:
                                          Sean McDonald @Sean_McDonald5
                                            2024-08-28 16:48:35.030Z

                                            Hi Christian,
                                            When I am attempting to take your advice, and re-copy and paste.
                                            I’m currently seeing this when booting SF today

                                            Any advice in what I might be doing wrong?

                                            https://www.dropbox.com/scl/fi/vfhqrrpbxafz413imi7pk/IMG_5067.MOV?rlkey=d3i72oeedlrd10vue8x83drcl&dl=0

                                            1. Hi Sean,

                                              This indicates it's not loading properly. I would try to restart SoundFlow. If that doesn't help, please open a new thread via Help/Issue so as to not burden the contributors to this thread (the issue you're seeing is not related to the topic of this thread).

                                              See more:
                                              https://soundflow.org/docs/help#help-issue