No internet connection
  1. Home
  2. How to

Select First Track? Unmute and Solo

By Jack Green @Jack_Green
    2022-04-20 15:23:05.133Z

    Hi,

    Very new and I know nothing about scripting...

    Basically looking to Select the first track in my session (This is always the Reference mix supplied by my client) Unmute it and solo it, Then on the next press Mute and Unsolo it. It always the first track of the session but i dont normally bother naming it anything special.

    Ive seen some posts on solo and muting, And some on selecting the last track of a session. But I dont know how to adapt the code to make it the first track.

    Thanks in advance

    Jack

    Solved in post #2, click to view
    • 5 replies
    1. Chris Shaw @Chris_Shaw2022-04-20 20:36:48.411Z2025-06-12 15:45:53.283Z

      This should do it:

      const desiredTrack = "first" // or "last"
      
      sf.ui.proTools.mainWindow.invalidate();
      
      function getSoloState(trackName) {
          const track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
          const trackHasSoloBtn = !track.title.invalidate().value.endsWith(" - Master Track ");
          return trackHasSoloBtn ? track.isSoloed : false;
      };
      
      // Get first visible track in session
      const visibleTrackNames = sf.ui.proTools.visibleTrackNames
      const firstTrack = visibleTrackNames[0];
      const lastTrack = visibleTrackNames[visibleTrackNames.length - 1];
      
      const targetTrack = desiredTrack == "first" ? firstTrack : lastTrack
      
      // Define first track solo button
      const firstSoloButton = sf.ui.proTools.trackGetByName({ name: targetTrack }).track.buttons.whoseTitle.is("Solo").first;
      
      if (getSoloState(firstTrack) == false) {  // If track isn't solo-ed unmute track and click solo button
          sf.ui.proTools.trackSetMuteByName({
              name: firstTrack,
              targetValue: 'Disable'
          });
      
          firstSoloButton.elementClick();
      
      } else {
      
          // If track is solo-ed mute track and click solo button
          sf.ui.proTools.trackSetMuteByName({
              name: firstTrack,
              targetValue: 'Enable'
          });
      
          firstSoloButton.elementClick();
      };
      
      ReplySolution
      1. Hey Chris!

        Any chance you could do a version for the latest track as well? I just can’t seem to crack it 🥲

        1. Hey @Artem_Shcherbakov,

          I edited the code above to do either.
          Just change desiredTrack at the top of the script to either "first" or "last" to do what you want.

          1. Thanks for the help, Chris! 🙏
            The updated script didn’t fully work for me just by changing "first" or "last" at the top — a few other lines still referenced the first track directly.
            Here’s the version I put together — not sure if it’s the most proper way to do it, but it works as expected for me :)

            const desiredTrack = "last"
            
            sf.ui.proTools.mainWindow.invalidate();
            
            function getSoloState(trackName) {
                const track = sf.ui.proTools.trackGetByName({ name: trackName }).track;
                const trackHasSoloBtn = !track.title.invalidate().value.endsWith(" - Master Track ");
                return trackHasSoloBtn ? track.isSoloed : false;
            };
            
            // Get first visible track in session
            const visibleTrackNames = sf.ui.proTools.visibleTrackNames
            const firstTrack = visibleTrackNames[0];
            const lastTrack = visibleTrackNames[visibleTrackNames.length - 1];
            
            const targetTrack = lastTrack
            
            // Define first track solo button
            const firstSoloButton = sf.ui.proTools.trackGetByName({ name: targetTrack }).track.buttons.whoseTitle.is("Solo").first;
            
            if (getSoloState(lastTrack) == false) {  // If track isn't solo-ed unmute track and click solo button
                sf.ui.proTools.trackSetMuteByName({
                    name: lastTrack,
                    targetValue: 'Disable'
                });
            
                firstSoloButton.elementClick();
            
            } else {
            
                // If track is solo-ed mute track and click solo button
                sf.ui.proTools.trackSetMuteByName({
                    name: lastTrack,
                    targetValue: 'Enable'
                });
            
                firstSoloButton.elementClick();
            };
            
      2. In reply toJack_Green:
        Jack Green @Jack_Green
          2022-04-21 09:22:05.029Z

          Worked perfectly

          Thankyou!!

          1. Progress
          2. @Jack_Green closed this topic 2022-04-21 09:22:18.373Z.
          3. @Jack_Green reopened this topic 2022-04-21 09:22:24.293Z.