No internet connection
  1. Home
  2. Support

How can I turn this script into a toggle dependent on first selected folder's open/closed state?

By Michael Feldman @Michael_Feldman
    2025-05-16 01:10:16.526Z

    Title

    How can I turn this script into a toggle dependent on first selected folder's open/closed state?

    What do you expect to happen when you run the script/macro?

    How can I modify this script so that it toggles folder state depending on the first selected track's open/closed state?

    Basically, I'd like it to act similarly to the built-in Open/Close Folder command in Pro Tools that toggles folders open/closed.

    I'm trying to avoid Pro Tools' built-in command because it has a glitch that causes CPU spikes in large sessions with dynamic plugin processing enabled every single time I open/close a folder. This script somehow gets around the CPU spike glitch.

    Are you seeing an error?

    What happens when you run this script?

    This script works perfectly, but I'd like to turn it into a toggle dependent on first selected track's open/closed state. I lack the programming skills to make this work.

    How were you running this script?

    I used a keyboard shortcut within the target app

    How important is this issue to you?

    4

    Details

    {
        "inputExpected": "How can I modify this script so that it toggles folder state depending on the first selected track's open/closed state?\n\nBasically, I'd like it to act similarly to the built-in Open/Close Folder command in Pro Tools that toggles folders open/closed.  \n\nI'm trying to avoid Pro Tools' built-in command because it has a glitch that causes CPU spikes in large sessions with dynamic plugin processing enabled every single time I open/close a folder.  This script somehow gets around the CPU spike glitch. ",
        "inputIsError": false,
        "inputWhatHappens": "This script works perfectly, but I'd like to turn it into a toggle dependent on first selected track's open/closed state.  I lack the programming skills to make this work.  ",
        "inputHowRun": {
            "key": "-Mpfwh4RkPLb2LPwjePT",
            "title": "I used a keyboard shortcut within the target app"
        },
        "inputImportance": 4,
        "inputTitle": "How can I turn this script into a toggle dependent on first selected folder's open/closed state? "
    }

    Source

    let selectedTracks = sf.ui.proTools.selectedTrackHeaders;
    
    sf.app.proTools.setTrackOpenState({
        trackNames: selectedTracks.map(t => t.normalizedTrackName),
        enabled: true,
    });
    
    
    

    Links

    User UID: pROqkdj7RKStj1Qc1BqhB3YPBJx1

    Feedback Key: sffeedback:pROqkdj7RKStj1Qc1BqhB3YPBJx1:-OQLd4K9GU97RoMy8bDs

    Feedback ZIP: kk27GhAyDvTeQA/OadVw8fuqVOdO5KjmDd8H3pQA2n+uxGyA1VEBkk09ek36iHoji3R9EQYO1yYYTQArhBR49kUOKWBHypWoRTInD9Lb3tBim0e5MMk5nRzuBcIc/VUfBJ3mo956d913vQh8Y38CzpV8xHOfj99wzG57mWVf9rnY9QbypBkndLK8h7XtXtFqsi+gfJIUA1+uGLfc6hPn1hBlGA5rV9lu1Oy6PJ13PgAE956SyKCODsagukRYHkZrEL4+I0ZPwdyi+2upLlEBXgPs1hGkevAjsPpG4DaDkiDnpuhVS6cYDyuuRFdGANSjSuQrqwUm0vKIBfu2OA6uPQ==

    • 1 replies
    1. Kitch Membery @Kitch2025-05-16 20:39:47.772Z

      Hi @Michael_Feldman

      This should do the trick :-)

      const selectedFolders = sf.app.proTools.tracks.invalidate().allItems
          .filter(t => !t.isHidden && t.type.endsWith("BasicFolder") && t.isSelected);
      
      if (selectedFolders.length > 0) {
          const targetState = !selectedFolders[0].isOpen;
          const trackNames = selectedFolders.map(t => t.name);
      
          sf.app.proTools.setTrackOpenState({
              trackNames,
              enabled: targetState,
          });
      }
      

      Let me know if that is what you're after. :-)