No internet connection
  1. Home
  2. How to

Drag or move track command?

By Graham Archer @Graham_Archer
    2019-09-10 23:11:12.924Z

    Hi there,

    I just wondered if anyone has had success dragging or moving tracks up or down in the track list in a session? Is this possible and is there a specific command for that?

    Thanks in advance!

    Graham

    • 16 replies

    There are 16 replies. Estimated reading time: 17 minutes

    1. Hi @Graham_Archer

      It is not a very easy or elegant thing to do right now, but this is a starting point for such a script. It will take the selected track and move it one track down:

      sf.ui.proTools.appActivateMainWindow();
      
      function getNextTrack() {
          var trackName = sf.ui.proTools.selectedTrackNames[0];
          var visibleIndex = sf.ui.proTools.visibleTrackNames.indexOf(trackName);
          return sf.ui.proTools.visibleTracks.trackHeaders[visibleIndex + 1];
      }
      
      var thisButtonFrame = sf.ui.proTools.selectedTrack.titleButton.frame;
      var nextTrack = getNextTrack();
      var nextFrame = nextTrack.frame;
      
      sf.mouse.simulateDrag({
          startPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: thisButtonFrame.y + thisButtonFrame.h / 2 },
          endPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: nextFrame.y + nextFrame.h / 2 + 20 }
      });
      
      1. What is the workflow you are trying to build? Maybe we can augment this script to do better, but I think it'll be easier if we understand the overall workflow you're aiming for.

        1. GGraham Archer @Graham_Archer
            2019-09-11 21:53:31.064Z

            Hey!

            Thanks for replying. So basically an auto-session organiser. I want to be able to sort tracks based on key words in the track names and move the tracks based on those key words. For example, I want the kick drum at the top of the session and I want vocals at the bottom. Something along the lines of "if track name has word 'kick' then move track upwards and colour it red". I'm going to need a way of delineating between groups of tracks but I haven't got that far yet......

            Does that make some sense? haha I hope so!

            Thank you!

            1. Sure that makes sense! While I get working on that, try to come up with a list of rules for this sorting process.
              It's a pretty complex and advanced script we're talking about here, so I can't make promises that we'll get it working (and it might take some time)

              1. GGraham Archer @Graham_Archer
                  2019-09-11 22:26:05.614Z

                  Hey,

                  Sure thing. I think at the very least, if it was possible to get groups of tracks together and coloured then that would save a lot of time. I'm sure it could work for post too, it would all depend on the key words really. In my head I'm thinking of a switch / case type programming scenario where by:

                  case 1 = keywords "Kick", "Snare", "Hi Hat", "Tom", "Toms", "Crash", "Cymbal", "Clap" etc. // Drums
                  case 2 = keywords "Bass", "P Bass", "808", "Sub Bass" etc. // Bass
                  case 3 = keywords "Guitar", "Acoustic", "GTR", "Gtr", "Strum", "Strumming" etc. // Guitars

                  and so on and so forth. And there would be a colour for each case - so the moment a track was identified by a keyword then it would be coloured a particular colour and then moved (or this could be a bubble sort type scenario here) to the correct position in the session. Something like if track keyword is case 2 move upwards until you reach a case 1 track.

                  I realise this is all easier said than done! But hopefully that gives you an idea of what's in my head in pseudo code.

                  Thanks!

                  1. GGraham Archer @Graham_Archer
                      2019-10-19 23:40:49.932Z

                      Hey @chrscheuer this script works great on it's own but I'm trying to re-use it multiple times in conjunction with sf.ui.proTools.trackSelectByName and I'm finding that after the first 'mouse drag' the track index is off for sf.ui.proTools.trackSelectByName when I go to select the next track. So basically it works great first time and then I go to use this script again, but now the track order has changed but it's still selecting the 'old' track order. Any ideas as to why that might be? Is there a way to 'flush' or re-assess the track index so that the second time I call this function the track index for the script is correct? Thanks in advance!

              2. In reply tochrscheuer:
                MMatt Barnes @Matt_Barnes
                  2022-05-04 17:39:58.286Z

                  Hey Christian,

                  Similar to Graham, I'm trying to build a mix prep helper that moves selected tracks to a specific location.

                  Is there a way to modify this script to move a track to be above a specifically named track?
                  E.g I would select my drum tracks and then trigger the script to move them beneath my drum bus.

                  Any help would be much appreciated!

                  Thanks!
                  Matt

                  1. Hi Matt,

                    I don't have time to look into this right at this moment, but try changing where I use "+ 1" to get to the next track and set it to be "- 1" or "- 2" or something like that.

                    1. MMatt Barnes @Matt_Barnes
                        2022-05-05 18:44:49.737Z

                        Amazing, thanks Christian,

                        Yes changing to "-2" put the track one space above which is great.

                        I altered the script to move all selected tracks to beneath by drum bus.
                        But it only works if the drum bus track is visible on the srcreen.

                        sf.ui.proTools.appActivateMainWindow();
                        
                        function getNextTrack() {
                            var trackName = sf.ui.proTools.selectedTrackNames[0];
                            return sf.ui.proTools.trackGetByName({ name: 'Drums' }).track ;
                        }
                        
                        var thisButtonFrame = sf.ui.proTools.selectedTrack.titleButton.frame;
                        var nextTrack = getNextTrack();
                        var nextFrame = nextTrack.frame;
                        
                        sf.mouse.simulateDrag({
                            startPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: thisButtonFrame.y + thisButtonFrame.h / 2 },
                            endPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: nextFrame.y + nextFrame.h / 2 + 20 }
                        });
                        
                        
                         
                        
                        1. Jonas Kroon @Jonas_Kroon
                            2022-10-20 10:29:59.772Z

                            Hi Matt!

                            Sorry about replying to an old thread.

                            This modification is great! I reckon it would be very useful in a mix prep script.

                            Did you manage to improve it further?

                            I was just wondering:

                            1. Would it be easy to modify the script so that it moves the selected track(s) just BEFORE another track, instead of just AFTER it?

                            2. Is there any way to make it work even if the target track is not visible on screen? Perhaps by making the script scroll to view the target track first, and then execute the move? I don't know, I'm not that strong a programmer.

                            Any suggestions would be much appreciated!

                    2. A
                      In reply toGraham_Archer:
                      Aidan Thillmann @Aidan_Thillmann
                        2022-05-03 16:28:22.138Z

                        @chrscheuer Hey! I know this is an old thread, but I'm trying to get this idea working in a larger script of mine, but instead of moving the track down one I'd like it to move it UP one. I want it to be part of a larger script where I select some tracks, it creates a new Aux from the "new track..." menu item, I name the Aux, it creates the Aux, makes the track height Medium, then moves it one track up. Every time I want a group of tracks to go to a new Aux I always move it up one slot because Pro Tools always creates the Aux below the first track in the selected group of tracks.

                        As a bonus it would be amazing if I could have a template or multiple versions of this script where I could select the output of the new Aux as well, but I already have a separate script for that.

                        1. MMatt Barnes @Matt_Barnes
                            2022-05-05 18:49:44.372Z

                            Changing the "+ 1" to a "-2" as Christian suggested worked for me

                            sf.ui.proTools.appActivateMainWindow();
                            
                            function getNextTrack() {
                                var trackName = sf.ui.proTools.selectedTrackNames[0];
                                var visibleIndex = sf.ui.proTools.visibleTrackNames.indexOf(trackName);
                                return sf.ui.proTools.visibleTracks.trackHeaders[visibleIndex - 2];
                            }
                            
                            var thisButtonFrame = sf.ui.proTools.selectedTrack.titleButton.frame;
                            var nextTrack = getNextTrack();
                            var nextFrame = nextTrack.frame;
                            
                            sf.mouse.simulateDrag({
                                startPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: thisButtonFrame.y + thisButtonFrame.h / 2 },
                                endPosition: { x: thisButtonFrame.x + thisButtonFrame.w / 2, y: nextFrame.y + nextFrame.h / 2 + 20 }
                            });
                            
                            
                            1. Cool! The downside is you'll need some special casing if this is the 2nd or 1st track already. If it's the 2nd track this will fail in moving it before the 1st track due to -2 ending up as a negative index.

                              1. AAidan Thillmann @Aidan_Thillmann
                                  2022-05-06 16:09:33.628Z

                                  Yeah I tried implementing this as Matt suggested, but when I select a bunch of tracks it always selects the output menu path from the LAST selected track. If I could get it to select the menu path from the FIRST selected track, then this would work, as Pro Tools would throw the new aux underneath the first selected track, then the mouse drag here should work. Here is that whole script of mine right now:

                                  sf.ui.proTools.appActivateMainWindow();
                                  sf.ui.proTools.invalidate();
                                  
                                  
                                  //  Get variable with selected tracks
                                  const originalSelectedTracks = sf.ui.proTools.selectedTrackNames
                                  
                                  //  Get last selected, and popup on that one. This will ensure the new track is allways created after the selected tracks
                                  const lastSelectedTrack = sf.ui.proTools.trackGetByName({ name: originalSelectedTracks[originalSelectedTracks.length - 1] }).track
                                  
                                  //  track Scroll to view
                                  lastSelectedTrack.trackScrollToView()
                                  
                                  // Select all again
                                  sf.ui.proTools.trackSelectByName({ names: originalSelectedTracks })
                                  
                                  // track output popup select, new track
                                  lastSelectedTrack.trackOutputSelect({
                                      outputPath: ["new track..."],
                                      selectForAllSelectedTracks: true,
                                  });
                                  
                                  
                                  const newTrackWin = sf.ui.proTools.windows.whoseTitle.is('New Track').first.elementWaitFor().element
                                  
                                  //  If format is not Stereo, change to Stereo
                                  if (newTrackWin.popupButtons.allItems[2].invalidate().value.value != "Stereo") {
                                      newTrackWin.popupButtons.whoseDescription.is('Track format').first.popupMenuSelect({
                                          menuPath: ["Stereo"],
                                      });
                                  }
                                  //  If type is not Aux Input, change to Aux Input
                                  if (newTrackWin.popupButtons.first.invalidate().value.value != "Aux Input") {
                                      newTrackWin.popupButtons.whoseDescription.is('Track type').first.popupMenuSelect({
                                          menuPath: ["Aux Input"],
                                      });
                                  }
                                  
                                  // Take your time to type the name of the new Aux.
                                  
                                  
                                  //  Wait forever for new track win to disapper
                                  newTrackWin.elementWaitFor({ waitType: "Disappear", timeout: -1 });
                                  
                                  
                                  // We just created a new track, so we need soundflow to get this info again
                                  sf.ui.proTools.invalidate()
                                  
                                  //  Get current selected tracks
                                  const currentSelectedTracks = sf.ui.proTools.selectedTrackNames
                                  
                                  // Just to be safe, deselect all tracks
                                  sf.ui.proTools.trackDeselectAll()
                                  
                                  // Get last selected track, should be your new aux
                                  const newTrack = sf.ui.proTools.trackGetByName({ name: currentSelectedTracks[currentSelectedTracks.length - 1] }).track
                                  
                                  //  New track scroll to view
                                  newTrack.trackScrollToView()
                                  
                            2. M
                              In reply toGraham_Archer:
                              Matt Wolach @Matt_Wolach
                                2023-09-08 20:01:13.656Z

                                Hi does anyone know what script to use for moving tracks down to the bottom of the pro tools session?

                                1. Randy Brown @Randy_Brown
                                    2025-02-10 01:58:20.900Z

                                    Hey Matt,

                                    Over a year late but better than never maybe hahah! Two things to know to get the most out of this:

                                    1. This works for the selected track (and multiple tracks). Delete the // on Line 11 to toggle a search for which track to move. No track selected also toggles this search.

                                    2. You can reverse this script and drag to the top by changing the 1000 on Line 26 to 0.

                                    Enjoy!

                                    function dragTrackToBottom() {
                                        sf.ui.proTools.appActivateMainWindow();
                                        sf.ui.proTools.mainWindow.invalidate();
                                    
                                        sf.ui.proTools.menuClick({ menuPath: ["Window", "Edit"], }); //Makes sure we are on Edit window. Ensures a vertical drag.
                                    
                                        if (sf.ui.proTools.selectedTrackCount === 0) { sf.ui.proTools.trackSelectByNameSearch() } //Toggles search for track if nothing is selected
                                    
                                        sf.ui.proTools.selectedTrack.invalidate();
                                    
                                        //sf.ui.proTools.trackSelectByNameSearch(); //Delete the slashes to toggle a search for which track should move
                                    
                                        //Ensures track title is clickable
                                        sf.ui.proTools.selectedTrack.trackScrollToView();
                                    
                                        //Get original track title coordinates
                                        let originalTrackX = sf.ui.proTools.selectedTrack.titleButton.frame.x
                                        let originalTrackY = sf.ui.proTools.selectedTrack.titleButton.frame.y
                                    
                                        //Modifies click point on track title for "drag" behavior. Unmodified coordinates can be used to adjust track size.
                                        let modifiedTrackX = originalTrackX + 50;
                                        let modifiedTrackY = originalTrackY + 5;
                                    
                                        sf.mouse.simulateDrag({
                                            startPosition: { "x": modifiedTrackX, "y": modifiedTrackY },
                                            endPosition: { "x": modifiedTrackX, "y": 1000 },
                                            // Set endPostion Y value to: 0 for "Drag to Top" and 1000 for "Drag to Bottom"
                                        });
                                    }
                                    
                                    dragTrackToBottom()
                                    

                                    Open to critiques from all btw, trying to get better!