No internet connection
  1. Home
  2. How to

How to check if there is a track with specific name?

By Sam Choi @Sam_Choi
    2020-10-15 18:51:23.052Z

    Hi

    I am trying to make a script that will check if there is a track named "RX Mon" and create the track if there isn't one. I checked out other posts on the forum, but for some reason I couldn't get them to work.

    Not really sure where to start with this one so if you guys have any suggestions, please help out.

    Thanks!

    Solved in post #2, click to view
    • 3 replies
    1. Chris Shaw @Chris_Shaw2020-10-15 20:05:38.558Z2020-10-15 20:33:51.633Z

      Here's a solution. It's very similar to another script I wrote a while ago - I don't script as fast as you think :)

      I'm assuming you want to create the RX Mon track like you asked earlier. I'm including my version of that script but free free to swap it out for the solution you use.

      This script will also find RX Mon even if it is hidden / not visible.
      When finished the RX Mon track will be highlighted and scrolled into view

      
      
      function doesTrackExist(searchForTrack) {
          var visibleIndex = sf.ui.proTools.visibleTrackNames.indexOf(searchForTrack);
          return visibleIndex
      }
      //// Main Program////
      var originalShownTracks = sf.ui.proTools.trackGetVisibleTracks().names;
      
      
      sf.ui.proTools.trackListMenu({
          menuItemName: "Show All Tracks",
      });
      var trackToFind = "RX Mon"
      
      if (doesTrackExist(trackToFind) == -1) {
      
          log("RX Mon track does not exist!", "Creating now")
      
          // Create "RX Mon" Track script
          sf.ui.proTools.menuClick({
              menuPath: ["Track", "New..."],
          });
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.elementWaitFor();
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseDescription.is('Track format').first.popupMenuSelect({
              menuPath: ["Stereo"],
          });
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.popupButtons.whoseDescription.is('Track type').first.popupMenuSelect({
              menuPath: ["Aux Input"],
          });
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.textFields.whoseTitle.is('Track Name').first.elementSetTextFieldWithAreaValue({
              value: "RX Mon",
          });
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.buttons.whoseTitle.is('Create').first.elementClick();
      
          sf.ui.proTools.windows.whoseTitle.is('New Tracks').first.elementWaitFor({
              waitType: "Disappear",
          });
      
          // Scroll new track into view
          sf.ui.proTools.selectedTrack.trackScrollToView();
      
          //Invalidate cache
          sf.ui.proTools.invalidate();
      
          // Instantiate Insert
          sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
              insertOrSend: 'Insert',
              pluginNumber: 1,
              pluginPath: ['multichannel plug-in', 'Instrument', 'RX 8 Monitor (stereo)']
          });
      
          // Solo Isolate track
          sf.ui.proTools.selectedTrack.buttons.whoseTitle.is('Solo').first.mouseClickElement({
              isCommand: true,
          });
      } else {log("RX Mon track exists!","Scrolling into view")}
      
      sf.ui.proTools.trackSelectByName({
          names: originalShownTracks,
          deselectOthers: true,
      });
      sf.ui.proTools.trackSelectByName({
          names: ["RX Mon"],
          deselectOthers: false,
      });
      sf.ui.proTools.trackListMenu({
          menuItemName: "Show Only Selected Tracks",
      });
      sf.ui.proTools.trackSelectByName({
          names: ["RX Mon"],
          deselectOthers: true,
      });
      sf.ui.proTools.selectedTrack.trackScrollToView();
      
      Reply3 LikesSolution
      1. SSam Choi @Sam_Choi
          2020-10-17 08:42:40.769Z

          Wow Chris this looks great! Thank you so much! I'm kinda new to scripting just in general and this helps a lot.

          1. In reply toChris_Shaw:
            TThomas Gloor @Thomas_Gloor
              2022-04-20 09:49:03.380Z2022-04-20 13:09:29.512Z

              Hey @Chris_Shaw

              Thank you for yet another awsome script!
              I'm building a session sorting macro, so I modified it as follow:

              . Bypass the whole "Create RX Mon track section", as it's not what I'm looking to do
              . declared constants that store the name of all tracks the start with the prefix KICK

              PROBLEM:

              I tried it within a session that has 4 tracks that starts with KICK but the script doesn't see them. It simply

               log(" There is no track using " + prefix + " as prefix", "Will hide //KICK TRACKS, make them inactive and move them to //UNUSED//")
              
              

              which is weird, because he obviously found the tracks :/

              My ultimate goal is to have your "Move tracks script" to move the tracks to the LAST SELECTED TRACK THAT STARTS WITH KICK.

              I'm an absolute begginer, so please pardon me if it's too much. Here's the code, in case you care to help.

              Best,

              T.

              function doesTrackExist(searchForTrack) {
                  var visibleIndex = sf.ui.proTools.visibleTrackNames.indexOf(searchForTrack);
                  return visibleIndex
              }
              
              //Prefix
              var prefix = "KICK" //<--------Prefix goes here
              
              //Find all tracks that use the prefix
              const allTrackNames = sf.ui.proTools.trackNames;
              const tracksWithPrefix = allTrackNames.filter(trackName => trackName.startsWith(prefix));
              
              
              //// Main Program////
              var originalShownTracks = sf.ui.proTools.trackGetVisibleTracks().names;
              
              /// Get Selected track names to variable
              const selectedTracks = sf.ui.proTools.selectedTrackNames
              
              sf.ui.proTools.trackListMenu({
                  menuItemName: "Show All Tracks",
              });
              
              var trackToFind = tracksWithPrefix   //<-----track name goes here
              
              if (doesTrackExist(trackToFind) == -1) {
              
                  log(" There is no track using " + prefix + " as prefix", "Will hide //KICK TRACKS, make them inactive and move them to //UNUSED//")
              
              } 
              
              else {log("There is at least one track using " + prefix + " as prefix","Scrolling into view and moving //KICK TRACKS next to it")}
              
              //Select all original visible tracks
              sf.ui.proTools.trackSelectByName({
                  names: originalShownTracks,
                  deselectOthers: true,
              });
              
              //Show only original visible tracks
              sf.ui.proTools.trackListMenu({
                  menuItemName: "Show Only Selected Tracks",
              });
              
              // Select track by name using variable selectedTracks
              sf.ui.proTools.trackSelectByName({ names: selectedTracks })
              
              sf.ui.proTools.selectedTrack.trackScrollToView();
              
              

              Thank you so much