No internet connection
  1. Home
  2. How to

How to check if a track exists?

By Nacho @Nacho_Sotelo
    2023-08-02 18:36:10.876Z

    I'm trying to make a simple script that solos 4 tracks, if one of those tracks is not present in the session, it should just solo the ones that are there. I thought with the onError: "Continue" would be enough, but seems like if "track 3" is not present in the session, itll still throw an error and stop there, failing to solo "track 4". Any ideas?

    sf.ui.proTools.mainWindow.invalidate();
    
    sf.ui.proTools.trackGetByName({ name: "track 1", makeVisible: true }).track.trackSetSolo({
        onError: "Continue",
    });
    
    sf.ui.proTools.trackGetByName({ name: "track 2", makeVisible: true }).track.trackSetSolo({
        onError: "Continue",
    });
    
    sf.ui.proTools.trackGetByName({ name: "track 3", makeVisible: true }).track.trackSetSolo({
        onError: "Continue",
    });
    
    sf.ui.proTools.trackGetByName({ name: "track 4", makeVisible: true }).track.trackSetSolo({
        onError: "Continue",
    });
    
    
    

    And this is the error:

    02.08.2023 13:33:11.48 <info> [Backend]: JavaScript error with InnerException: null
    !! Command Error: Solo D&B [user:ck8ko0s09000f2210f6n002uz:clksnvsg80000ap10sxg9iqhs]:
    TypeError: Cannot read property 'trackSetSolo' of null
    (Solo D&B line 11) 
    
    • 5 replies
    1. S
      SoundFlow Bot @soundflowbot
        2023-08-02 18:36:13.724Z

        Thanks for contacting SoundFlow support.

        Please note, that the best way to get help with a script, macro or other content installed from the Store or content that you've made yourself, is to select the script/macro, then click the red Need help button, and then click "Get help with this script or macro".
        By using this method, we will get access to more information and so should be able to help you quicker.
        You can read more about how this works here: bit.ly/sfscripthelp

        If you're seeing an error that isn't related to scripts or macros, and you think this is a bug in SoundFlow, please file a Help/Issue bug report.
        You can see how to do this by going to bit.ly/sfhelpissue

        1. In reply toNacho_Sotelo:

          @Nacho_Sotelo, here you go!

          /** @param {{ trackNames: string[] }} arg */
          function soloTracks({ trackNames }) {
              sf.ui.proTools.mainWindow.invalidate();
          
              trackNames.forEach(name => {
                  const track = sf.ui.proTools.trackGetByName({ name, makeVisible: true }).track;
                  if (track) track.trackSetSolo();
              });
          }
          
          soloTracks({
              trackNames: ["track 1", "track 2", "track 3", "track 4"]
          });
          
          1. NNacho @Nacho_Sotelo
              2023-08-02 22:18:59.410Z

              Thank you Raphael!

              Any idea why the onError: "Continue" does not work?

              Your script works perfectly but takes just a bit more time to complete after triggering it.

              1. When the trackGetByName method doesn't find a track, it returns null instead of throwing an error. So onError doesn't do anything since technically no error has occurred. We need to handle that case ourselves to get the desired result. The way I scripted it above is my preferred way of doing that.

                From a quick test, I see that both approaches take the same amount of time if all the tracks are present, but if one or more are missing, it suddenly takes a bit longer—and that's again because of the trackGetByName method, which seems to retry a few times before returning null.

                1. NNacho @Nacho_Sotelo
                    2023-08-03 18:41:20.454Z

                    Understood, thanks a lot!