No internet connection
  1. Home
  2. How to

Move Tracks to its IO Routing Folder

By Vanessa Garde @Vanessa_Garde
    2023-06-26 16:04:55.480Z

    Hi there,

    I am trying to route a bunch of audio tracks to their own Routing Folder (based on the output of the track, and the input of the routing folder).

    When I do it with many selected tracks, they all move to the routing folder of the first track selected.
    How can we iterate the selected tracks and make that every one go to their own corresponding routing folder?

    Many thanks!

    Vanessa G.

    
    const app = sf.ui.proTools
    app.appActivate();
    app.mainWindow.invalidate();
    
    // Get selected tracks
    const originalSelectedTracks = app.selectedTrackNames;
    
    
    // Get first visible track
    var firstVisibleTrack = app.visibleTrackNames[0]
    
    // Get first track's output
    var memberOutput = app.selectedTrack.groups.whoseTitle.is("Audio IO").whoseTitle.is("Audio IO").first.popupButtons.allItems[1].value.invalidate().value
    
    
    sf.ui.proTools.trackGotoByInputName({
        inputName: memberOutput,
    });
    
    var RoutingFolder = sf.ui.proTools.selectedTrackNames[0];
    //log(RoutingFolder);
    
    // Re-select original tracks
    sf.ui.proTools.trackSelectByName({
        names: originalSelectedTracks
    });
    
    
    sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({ menuPath: ['Move to...', RoutingFolder], isRightClick: true, });
    
    • 7 replies
    1. V
      Vanessa Garde @Vanessa_Garde
        2023-06-26 16:08:46.675Z

        PS. Trying incorporating it with this with no luck...

        1. VVanessa Garde @Vanessa_Garde
            2023-06-26 16:21:41.877Z

            This is what I have so far... (not working):

            const app = sf.ui.proTools
            app.appActivate();
            app.mainWindow.invalidate();
            
            var originallySelectedTrackNames = sf.ui.proTools.selectedTrackNames.slice()
            for (var i in originallySelectedTrackNames) {
                 sf.ui.proTools.trackSelectByName({
                      names: [originallySelectedTrackNames[i]],
                  });
                  //Your Code Here
                            // Get first track's output
                        var memberOutput = app.selectedTrack.groups.whoseTitle.is("Audio IO").whoseTitle.is("Audio IO").first.popupButtons.allItems[1].value.invalidate().value
            
            
                        sf.ui.proTools.trackGotoByInputName({
                            inputName: memberOutput,
                        });
            
                        var RoutingFolder = sf.ui.proTools.selectedTrackNames[0];
                        log(RoutingFolder);
            
                        // Re-select original tracks
                        sf.ui.proTools.trackSelectByName({
                            names: originallySelectedTrackNames[i]
                        });
            
            
                        sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({ menuPath: ['Move to...', RoutingFolder], isRightClick: true, });
            
            
            
                  log(originallySelectedTrackNames[i]);
            }
            
            sf.ui.proTools.trackSelectByName({ names: originallySelectedTrackNames });
            
          • F
            In reply toVanessa_Garde:
            Forrester Savell @Forrester_Savell
              2023-06-27 21:52:20.411Z

              Hi @Vanessa_Garde

              I use a similar script I put together that I think will do this for you. After selecting the tracks you wish to route, it asks if you want to create a Routing Folder or Aux, then Stereo or Mono. It will route selected tracks to the new Folder/Aux and use their output as the output of that Folder/Aux, plus create an input and group for the selected tracks, using the name you choose. It doesn't use the loop function for multiple tracks, like you've linked, it just applies the same output to all the selected tracks. Hope you find that helpful.

              sf.ui.proTools.appActivateMainWindow();
              
              // if visible, hide floating windows
              const areFloatingWindowsVisible = sf.ui.proTools.getMenuItem('Window', 'Hide All Floating Windows').isEnabled
              if (areFloatingWindowsVisible) {
                  sf.ui.proTools.menuClick({ menuPath: ['Window', 'Hide All Floating Windows'] })
              };
              
              /// store selected track names
              const selectedTracks = sf.ui.proTools.selectedTrackNames
              const firstSelectedTrack = selectedTracks[0];
              
              
              function scrollToTrackNamed(trackName, selectedTracks) {
                  // Open scroll to track dialog and enter track name
                  sf.ui.proTools.menuClick({ menuPath: ['Track', 'Scroll to Track...'] });
                  var confirmationDialogWin = sf.ui.proTools.confirmationDialog;
              
                  confirmationDialogWin.elementWaitFor();
              
                  confirmationDialogWin.textFields.first.elementSetTextFieldWithAreaValue({ value: trackName });
              
                  confirmationDialogWin.buttons.whoseTitle.is('OK').first.elementClick();
              
                  confirmationDialogWin.elementWaitFor({ waitType: 'Disappear' });
              
                  //Re-select originally selected tracks
                  sf.ui.proTools.trackSelectByName({ names: selectedTracks })
              };
              
              
              
              scrollToTrackNamed(firstSelectedTrack, selectedTracks);
              
              
              
              // Try making new Routing/Aux track
              try {
              
                  // define track output selector
                  const audioOutput = sf.ui.proTools.selectedTrack.groups.whoseTitle.is("Audio IO")
                  const trackOutput = audioOutput.first.popupButtons.allItems[1]
              
                  // get ouput of first track
                  var outputPaths = trackOutput.popupMenuFetchAllItems().menuItems
                  const outputPath = outputPaths.map((mi, i) => ({ menuItem: mi, index: i })).filter(m => m.menuItem.element.isMenuChecked)[0].menuItem.path;
              
                  // Get track and bus info from user
                  var trackType = sf.interaction.displayDialog({
                      buttons: ["Cancel", "Routing Folder", "Aux Input"],
                      defaultButton: 'Routing Folder',
                      prompt: "Which do you want to create?",
                  }).button;
              
                  var trackWidth = sf.interaction.displayDialog({
                      buttons: ["Cancel", "Stereo", "Mono"],
                      defaultButton: 'Stereo',
                      prompt: "New Track Width?",
                  }).button;
              
                  var busName = sf.interaction.popupText({
                      title: "Bus Name",
                  }).text;
              
                  sf.ui.proTools.appActivateMainWindow();
              
                  // If selected, create new Aux track
                  if (trackType == "Aux Input") {
                      sf.ui.proTools.menuClick({
                          menuPath: ['Track', 'New...']
                      });
              
                      const newTrackWin = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first
              
                      newTrackWin.elementWaitFor();
              
                      newTrackWin.popupButtons.whoseDescription.is("Track format").first.popupMenuSelect({
                          menuPath: [trackWidth]
                      });
              
                      newTrackWin.popupButtons.whoseDescription.is("Track type").first.popupMenuSelect({
                          menuPath: [trackType]
                      });
              
                      newTrackWin.textFields.whoseTitle.is("Track Name").first.elementClick();
              
                      newTrackWin.textFields.whoseTitle.is("Track Name").first.elementSetTextFieldWithAreaValue({
                          value: busName,
                      });
                      newTrackWin.buttons.whoseTitle.is("Create").first.elementClick();
              
                      /* Re-select original tracks */
                      sf.ui.proTools.mainWindow.invalidate();
              
                      sf.ui.proTools.trackSelectByName({ names: selectedTracks });
              
                      // Route selected tracks to new track
                      trackOutput.popupMenuSelect({
                          isShift: true,
                          isOption: true,
                          menuPath: ["track", busName + "*"],
                          useWildcards: true,
                      });
              
                      // Otherwise create new folder track
              
                  } else {
                      // Create new Folder Track
                      sf.ui.proTools.menuClick({
                          menuPath: ["Track", "Move to New Folder..."],
                      });
              
                      const newFolderWin = sf.ui.proTools.windows.whoseTitle.is("Move To New Folder").first
              
                      newFolderWin.elementWaitFor()
              
                      newFolderWin.popupButtons.first.popupMenuSelect({
                          menuPath: ["Routing Folder"],
                          useWildcards: false,
                      });
              
                      var isChecked = newFolderWin.checkBoxes.whoseTitle.is("Route Tracks to New Folder").first.isCheckBoxChecked;
                      if (!isChecked) {
                          newFolderWin.checkBoxes.whoseTitle.is("Route Tracks to New Folder").first.elementClick();
                      };
                      newFolderWin.textFields.whoseTitle.is("Track Name").first.elementSetTextFieldWithAreaValue({
                          value: busName,
                      });
                      newFolderWin.popupButtons.whoseDescription.is("Track format").first.popupMenuSelect({
                          menuPath: [trackWidth]
                      });
                      newFolderWin.buttons.whoseTitle.is("Create").first.elementClick();
              
                  };
              
                  // Route newly created trackto original track output
                  sf.ui.proTools.mainWindow.invalidate();
              
                  sf.ui.proTools.trackSelectByName({ names: [busName] });
              
              
                  sf.ui.proTools.selectedTrack.groups.whoseTitle.is("Audio IO").first.
                      popupButtons.whoseTitle.contains("Audio Output").first.popupMenuSelect({
                          menuPath: outputPath,
                      });
              
                  // Call up gropup window (if selected at start of script)
              
                  // Select original tracks
                  sf.ui.proTools.trackSelectByName({ names: selectedTracks });
              
                  // Restore floating windows
                  if (areFloatingWindowsVisible) {
                      sf.ui.proTools.menuClick({
                          menuPath: ['Window', 'Hide All Floating Windows']
                      })
                  };
                  // open Create Group WIndow
                  sf.ui.proTools.menuClick({
                      menuPath: ['Track', 'Group...']
                  });
              
                  sf.ui.proTools.createGroupDialog.elementWaitFor();
              
                  sf.ui.proTools.createGroupDialog.textFields.first.elementSetTextFieldWithAreaValue({
                      value: busName,
                  });
              
                  sf.ui.proTools.createGroupDialog.buttons.whoseTitle.is("OK").first.elementClick();
              
              
              } catch (err) {
                  // If user cancels or there is an error restore floating windows
              } finally {
                  if (areFloatingWindowsVisible) {
                      sf.ui.proTools.menuClick({
                          menuPath: ['Window', 'Hide All Floating Windows']
                      })
                  };
              }
              if (selectedTracks.length == 0) { log("No Tracks Selected", "") };
              
              
              1. VVanessa Garde @Vanessa_Garde
                  2023-06-28 14:26:01.404Z

                  Many thanks for the advice, @Forrester_Savell !
                  I might take a few ideas from that...!

                  So far, I am trying to get my first/initial script working in multiple tracks, I think I am close...! But not here yet...

                  
                  const app = sf.ui.proTools
                  app.appActivate();
                  app.mainWindow.invalidate();
                  
                  
                  //Get selected tracks
                  const originalTracks = sf.ui.proTools.selectedTrackNames;
                  
                  function action() {
                  
                  /// Code to repeat on every selected track goes here.
                  
                  
                  
                              var memberOutput = app.selectedTrack.groups.whoseTitle.is("Audio IO").whoseTitle.is("Audio IO").first.popupButtons.allItems[1].value.invalidate().value
                              var tempSelect = app.selectedTrackNames;
                              
                  
                  
                              sf.ui.proTools.trackGotoByInputName({
                                  inputName: memberOutput,
                              });
                  
                              var RoutingFolder = sf.ui.proTools.selectedTrackNames[0];
                              log(RoutingFolder);
                  
                              // Re-select original tracks
                              sf.ui.proTools.trackSelectByName({
                                  names: tempSelect
                                  // names: originalTracks[i]
                              });
                  
                  
                              sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({ menuPath: ['Move to...', RoutingFolder], isRightClick: true, });
                  
                  }
                  
                  
                  
                  //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. FForrester Savell @Forrester_Savell
                      2023-06-28 23:42:51.023Z

                      It looks as though you're attempting to move the tracks to a 'Routing Folder' that hasn't been created yet (line 35). So you'd either need to add code that converts the logged 'Routing Folder' Aux to a routing folder, or create a new one first.

                      1. VVanessa Garde @Vanessa_Garde
                          2023-06-29 07:45:08.168Z

                          Folders are created first on the template:

                          Many thanks for the back-forth on this @Forrester_Savell . :-)

                          1. FForrester Savell @Forrester_Savell
                              2023-07-01 05:03:00.244Z

                              Hi @Vanessa_Garde

                              Sorry it took me a minute to realize what you're after, then it took me a lot of minutes to work out why the loop didn't work, haha.

                              I think this code will do what you want, with the caveat that the Folder tracks need to be below the Audio tracks selected to move (like in your photo).
                              It's not thoroughly error checked - I've noticed weirdness, like the inability to select the Move To... menu if there are hidden tracks above the Audio tracks that are selected to move. Let me know how it goes for you.

                              const app = sf.ui.proTools
                              app.appActivate();
                              app.mainWindow.invalidate();
                              
                              var originallySelectedTrackNames = sf.ui.proTools.selectedTrackNames.slice();
                              
                              function scrollToTrackNamed(trackName, selectedTracks) {
                                   // Open scroll to track dialog and enter track name
                                   sf.ui.proTools.menuClick({ menuPath: ['Track', 'Scroll to Track...'] });
                                   var confirmationDialogWin = sf.ui.proTools.confirmationDialog;
                              
                                   confirmationDialogWin.elementWaitFor();
                              
                                   confirmationDialogWin.textFields.first.elementSetTextFieldWithAreaValue({ value: trackName });
                              
                                   confirmationDialogWin.buttons.whoseTitle.is('OK').first.elementClick();
                              
                                   confirmationDialogWin.elementWaitFor({ waitType: 'Disappear' });
                              
                                   //Re-select originally selected tracks
                                   sf.ui.proTools.trackSelectByName({ names: selectedTracks })
                              };
                              
                              //Scrolls to first selected track to make sure visible so code can run
                              scrollToTrackNamed(originallySelectedTrackNames[0], originallySelectedTrackNames)
                              
                              //loop Move to... for as many times as there were tracks selected. **** only works if Folder tracks are BELOW the tracks being moved
                              function moveTracks() {
                                   for (var i = 0; i < sf.ui.proTools.selectedTrackCount; i++) {
                              
                                        //select only first track of original selection
                                        sf.ui.proTools.trackSelectByName({
                                             names: [originallySelectedTrackNames[0]]
                                        });
                              
                                        //store first track's Output name
                                        var memberOutput = app.selectedTrack.groups.whoseTitle.is("Audio IO").whoseTitle.is("Audio IO").first.popupButtons.allItems[1].value.invalidate().value
                              
                                        //select track(Folder) that has same input as "memberOutput" **** potential for errors here if multiple tracks have this input
                                        sf.ui.proTools.trackGotoByInputName({
                                             inputName: memberOutput,
                                        });
                              
                                        //store the name of the Folder track
                                        var routingFolder = sf.ui.proTools.selectedTrackNames[0];
                              
                                        // Re-select first selected track to Move
                                        sf.ui.proTools.trackSelectByName({
                                             names: [originallySelectedTrackNames[0]]
                                        });
                              
                                        //Move to... first selected track to store Routing Folder
                                        sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({ menuPath: ['Move to...', routingFolder], isRightClick: true, });
                              
                                        // Re-select original tracks **** as first track has moved, process continues on the next track
                                        sf.ui.proTools.trackSelectByName({
                                             names: originallySelectedTrackNames
                                        });
                                   }
                              }
                              
                              moveTracks();