No internet connection
  1. Home
  2. How to

Is there a script to un-fold and fold folder tracks?

By John Costello @John_Costello
    2020-11-21 18:34:38.076Z

    Hello fellow SoundFlowians!

    I'm searching for the best way to un-fold and fold folder tracks in the mix window. The included SoundFlow scripts to not seem to work for me. Is this a PT 2020.11 thing? My approach has been to use the select track macro, convert to a script and try and bolt on some folder code from an old post. I had something kind of working, but now it has stopped functioning. Thank you all for helping someone who is not quite up to speed on code writing yet.

    Solved in post #6, click to view
    • 38 replies

    There are 38 replies. Estimated reading time: 36 minutes

    1. Hey John,

      Yeah, this one is short and sweet. Just replace folderNameGoesHere with the name of the folder!

      sf.ui.proTools.trackGetByName({ name: "folderNameGoesHere" }).track.folderTrackSetOpen({
          targetValue: 'Toggle',
      });
      
      1. John Costello @John_Costello
          2020-11-21 19:04:39.624Z

          Hi Raphael!

          Do you mean the track name goes there?

          1. Yup! The name of the folder track you'd like fold/un-fold. For example, if the folder track is called GTRS, then you would do this:

            sf.ui.proTools.trackGetByName({ name: "GTRS" }).track.folderTrackSetOpen({
                targetValue: 'Toggle',
            });
            
            1. John Costello @John_Costello
                2020-11-21 19:35:51.858Z

                Heya Raphael!

                Thanks for jumping in on this!

                When I put in (Exact correct folder track name.) this:

                sf.ui.proTools.trackGetByName({ name: "VCAs" }).track.folderTrackSetOpen({
                    targetValue: 'Toggle',
                });
                

                I get this error:

                Folder Open/Close state didn't update ) VCAs Folder Toggle: Line 1)

                Do I need any additional script before or after?

                1. Mmm.. I tried to replicate that error but couldn't get it. Give the script below a shot:

                  sf.ui.proTools.appActivateMainWindow();
                  
                  sf.ui.proTools.invalidate().trackGetByName({ name: "VCAs" }).track.folderTrackSetOpen({
                      targetValue: 'Toggle',
                  });
                  

                  Let me know if that works, if not, could you take a screenshot of the Edit Window in Pro Tools so I can see how you have it laid out. Maybe I'm missing something there.

                  Reply1 LikeSolution
                  1. John Costello @John_Costello
                      2020-11-21 20:18:05.411Z

                      Yay!

                      Very brilliant Raphael! That was the solution! I feel like I can breath again! A big part of my workflow is drilling in and out of my monster sized mixes! Who says you can't have your cake and eat it also! Thank you!

                      1. Perfect, glad that did the trick!

                      2. MMichael Keeley @Michael_Keeley
                          2021-01-28 23:33:04.811Z

                          Hi Raphael, Thanks for the code. The only way that I was able to get it to work was to create a new Routing folder then it would work for about 5 minutes. After that I get the following error below in the screen shot. Does anyone know what the issue is?

                          Thanks!!

                          1. Hey Michael! I answered your question over here: Could not click open close folder Line 3 error #post-2

                2. J
                  In reply toJohn_Costello:
                  junegate @junegate
                    2021-01-20 10:25:54.569Z

                    Hi guys, there's a way to fold and un-fold all the folder in a project without specify the name ?

                    1. John Costello @John_Costello
                        2021-01-20 16:24:09.041Z

                        I am wondering about this as well. The ability to seamlessly navigate a session using folder tracks is very important in large sessions. I wouldn't even mind if a global "Close all folder tracks." to also included nested folder tracks. Love my SoundFlow...

                        1. samuel henriques @samuel_henriques
                            2021-01-20 20:19:10.059Z

                            Hello guys,
                            this is working for me to close all folder tracks, including nested.
                            Open all is a bit trickier, but I should be able to find a way.

                            function selectAllFolderTracks() {
                            
                              var visibleTracks = sf.ui.proTools.trackGetVisibleTracks().names
                              var firstTrackFound;
                              let foundTracks = [];
                            
                              while (true) {
                            
                                sf.ui.proTools.trackDeselectAll();
                            
                                for (var i = 0; i < visibleTracks.length; i++) {
                            
                                  var trackIsFolder = sf.ui.proTools.trackGetByName({ name: visibleTracks[i] }).track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder')
                            
                                  if (trackIsFolder.exists)
                            
                                    if (trackIsFolder) {
                                      if (!firstTrackFound) { // Scroll to first track found
                                        sf.ui.proTools.trackGetByName({ name: visibleTracks[i], }).track.trackScrollToView();
                                        firstTrackFound = !firstTrackFound;
                                      } else {
                                        sf.ui.proTools.trackSelectByName({ names: [visibleTracks[i]], deselectOthers: false });
                                      }
                                      foundTracks.push(visibleTracks[i]);
                                    }
                                }
                                if (foundTracks.length !== 0) {
                                  break;
                                }
                                throw 0;
                              }
                            }
                            
                            
                            function closeFolderTracks() {
                            
                              sf.ui.proTools.appActivateMainWindow();
                              sf.ui.proTools.windows.invalidate();
                            
                              selectAllFolderTracks()
                            
                              const selectedTracks = sf.ui.proTools.selectedTrackNames.reverse()
                            
                              for (var i = 0; i < selectedTracks.length; i++) {
                            
                                sf.ui.proTools.invalidate().trackGetByName({ name: selectedTracks[i] }).track.folderTrackSetOpen({
                                  targetValue: 'Disable',
                                });
                              }
                            
                            }
                            
                            closeFolderTracks()
                            
                            1. John Costello @John_Costello
                                2021-01-20 20:27:59.189Z

                                Very cool Samuel! Yes I'm opening folder tracks currently by track name, which takes up many StreamDeck buttons. Would love to see an "Open all". Thank you so much for posting this script!!! JC3

                                PS When I use this it makes me feel like I'm "Cleaning up." my session!

                                1. samuel henriques @samuel_henriques
                                    2021-01-29 10:51:01.629Z

                                    Hey @John_Costello,
                                    Here's a version to open all folder tracks.
                                    Thank you @raphaelsepulveda, lots of code from the close and open folder tracks was taken from other scripts he shared.

                                    
                                    
                                    function selectAllFolderTracks() {
                                    
                                      var visibleTracks = sf.ui.proTools.trackGetVisibleTracks().names
                                      var firstTrackFound;
                                      let foundTracks = [];
                                    
                                    
                                      while (true) {
                                    
                                        sf.ui.proTools.trackDeselectAll();
                                    
                                        for (var i = 0; i < visibleTracks.length; i++) {
                                    
                                          var trackIsFolder = sf.ui.proTools.trackGetByName({ name: visibleTracks[i] }).track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Open Folder')
                                    
                                    
                                          if (trackIsFolder.exists)
                                    
                                            if (trackIsFolder) {
                                              if (!firstTrackFound) { // Scroll to first track found
                                                sf.ui.proTools.trackGetByName({ name: visibleTracks[i], }).track.trackScrollToView();
                                                firstTrackFound = !firstTrackFound;
                                              } else {
                                                sf.ui.proTools.trackSelectByName({ names: [visibleTracks[i]], deselectOthers: false });
                                              }
                                              foundTracks.push(visibleTracks[i]);
                                            }
                                        } if (foundTracks.length !== 0) {
                                          break;
                                        } else if (foundTracks.length == 0) {
                                          throw 0
                                        }
                                      }
                                    }
                                    
                                    
                                    function openFolderTracks() {
                                    
                                      sf.ui.proTools.appActivateMainWindow();
                                    
                                      while (true) {
                                    
                                        selectAllFolderTracks()
                                    
                                        const selectedTracks = sf.ui.proTools.selectedTrackNames
                                    
                                        if (selectedTracks.length >= 1) {
                                    
                                          if (selectedTracks.length == 1) {
                                    
                                            sf.ui.proTools.selectedTrack.folderTrackSetOpen({
                                              targetValue: 'Enable',
                                              onError: 'Continue'
                                            });
                                    
                                          } if (selectedTracks.length >= 2) {
                                    
                                            for (var i = 0; i < selectedTracks.length; i++) {
                                    
                                              sf.ui.proTools.invalidate().trackGetByName({ name: selectedTracks[i] }).track.folderTrackSetOpen({
                                                targetValue: 'Enable',
                                              });
                                              
                                            }
                                          }
                                        }
                                      }
                                    }
                                    
                                    
                                    openFolderTracks()
                                    
                                    
                                    
                                    
                                    
                                    1. Jjunegate @junegate
                                        2021-01-29 15:25:31.897Z

                                        guys you're amazing!!
                                        I just want to report that both scripts doesn't work if tracks are very little in vertical zoom. There's a way to fix that?

                                        1. samuel henriques @samuel_henriques
                                            2021-01-29 15:56:05.714Z

                                            Hey @junegate, thank you.
                                            You are right, if the folder icon is not visible, it won't work.
                                            @raphaelsepulveda has a fix for that, I'll try to add it and let you know.

                                          • John Costello @John_Costello
                                              2021-01-29 17:04:51.525Z

                                              Heya Samuel!

                                              Love this!!!!! Thank you!

                                              1. Joe Costable @Joe_Costable
                                                  2021-11-04 15:47:46.135Z

                                                  This works great alone, but I cannot get it to continue on to the rest of my script, and can't figure out why... is it stuck in the loop?

                                        2. M
                                          In reply toJohn_Costello:
                                          Michael Keeley @Michael_Keeley
                                            2021-01-29 19:34:26.311Z

                                            Thanks for these great scripts guys!

                                            I was wondering though is it possible to have a script that would select all tracks in the session then do a shift F to toggle the folders open and closed. This way it doesn't matter if the track folders are mini or micro. And it happens a lot faster when you have 20+folders

                                            Thanks so much!

                                            1. samuel henriques @samuel_henriques
                                                2021-01-29 19:52:04.813Z2021-01-29 19:58:30.978Z

                                                whoww! Thanks for that, never noticed shift+f, 🤯!!

                                                Was trying that exact thing but with code, hahaha!!

                                                here you go:

                                                sf.ui.proTools.appActivateMainWindow();
                                                sf.ui.proTools.invalidate();
                                                
                                                // Make sure we're on the Edit window.
                                                if (!sf.ui.proTools.getMenuItem("Window", "Edit").isMenuChecked) {
                                                    sf.ui.proTools.menuClick({
                                                        menuPath: ["Window", "Edit"],
                                                    })
                                                };
                                                
                                                let folderTracks = sf.ui.proTools.visibleTrackHeaders.filter(x => x.title.value.match("Folder")).map(n => n.title.value.split(" -").slice(0, 1).join())
                                                
                                                if (folderTracks.length >= 1) {
                                                
                                                    sf.ui.proTools.trackSelectByName({
                                                        names: folderTracks
                                                    })
                                                
                                                    sf.keyboard.press({
                                                        keys: "shift+f",
                                                    });
                                                }
                                                

                                                Hope this does it!!

                                                1. samuel henriques @samuel_henriques
                                                    2021-01-29 19:57:55.801Z

                                                    Made it select only folder tracks to make it less scary, but it's possible to select all tracks.

                                                    1. samuel henriques @samuel_henriques
                                                        2021-01-29 20:41:46.156Z

                                                        Just found this works if you keep all folders and subfolders open. Otherwise the closed subfolder won't be selected and thus open/closed.

                                                      • PPhilip weinrobe @Philip_weinrobe
                                                          2022-01-17 17:51:52.013Z

                                                          hi @samuel_henriques
                                                          this script above is really really efficient always works great.
                                                          however, it only toggles. could this script instead open or close depending on a changed variable?

                                                          1. samuel henriques @samuel_henriques
                                                              2022-01-17 18:23:59.788Z

                                                              Here you go, let me know if this is it.

                                                              /**
                                                              * @param {"Disable"|"Enable"} targetValue
                                                              */
                                                              function folderTrackSetOpen(targetValue) {
                                                                  sf.ui.proTools.appActivateMainWindow();
                                                                  sf.ui.proTools.invalidate();
                                                              
                                                                  // Make sure we're on the Edit window.
                                                                  if (!sf.ui.proTools.getMenuItem("Window", "Edit").isMenuChecked) {
                                                                      sf.ui.proTools.menuClick({
                                                                          menuPath: ["Window", "Edit"],
                                                                      })
                                                                  };
                                                              
                                                                  let folderTracks = sf.ui.proTools.visibleTrackHeaders.filter(x => x.title.value.endsWith("Folder Track "))
                                                              
                                                                  folderTracks.forEach(folder => {
                                                                      folder.folderTrackSetOpen({ targetValue: targetValue });
                                                                  })
                                                              }
                                                              
                                                              /// "Disable" to close | "Enable" to open
                                                              folderTrackSetOpen("Enable")
                                                              
                                                              1. PPhilip weinrobe @Philip_weinrobe
                                                                  2022-01-17 19:37:01.750Z

                                                                  perfect!

                                                          2. M
                                                            In reply toJohn_Costello:
                                                            Michael Keeley @Michael_Keeley
                                                              2021-01-29 21:07:55.414Z

                                                              Thanks so much! That works great and is a lot faster!

                                                              1. C
                                                                In reply toJohn_Costello:
                                                                Cooper Babbes @cooper
                                                                  2021-10-21 23:22:32.308Z

                                                                  Is there a way to do this one-way?

                                                                  i.e. set the status of a specific folder track to be closed, and do nothing if it's already closed. And even more difficult, do this even if the folder track is Mini or Micro height.

                                                                  Even more specifically in my case, I want to close and mute a specific folder track, even if it already happens to be either closed or muted, and open and unmute another folder track and all its subtracks, even if it's already open and/or unmuted. (I can do the muting actions with built in actions, not sure about one-way track toggling though.)

                                                                  1. samuel henriques @samuel_henriques
                                                                      2021-11-06 15:24:50.597Z2021-11-08 11:51:09.552Z

                                                                      Hello @Cooper_Babbes,

                                                                      This bit controls the script:

                                                                      ///  Set settings here
                                                                      folderSetOpenAndMuteState({
                                                                          trackName: "Folder Track Name",   //  Folder track name for action
                                                                          openFolder: "Enable",             // Enable or Disable or Toggle to open, close or toggle folder
                                                                          setMute: "Mute"                   // Mute, Unmute or Toggle Folder track
                                                                      })
                                                                      
                                                                      

                                                                      Change the parameters to suite your needs and duplicate the this lines for multiple tracks.

                                                                      It will work if tracks are smaller than small by changing the size.

                                                                      If you would you like them to go back to the original size, try this first to see if it's what you are looking for, then let me know and I'll add that part.

                                                                      Let me know how it works.

                                                                      
                                                                      function setTrackSize(size) {
                                                                      
                                                                          const f = sf.ui.proTools.selectedTrack.frame;
                                                                          const popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                                                                              relativePosition: { x: f.w - 10, y: 5 },
                                                                              isOption: true,
                                                                              isShift: true,
                                                                          }).popupMenu;
                                                                          popupMenu.menuClickPopupMenu({
                                                                              menuPath: [size]
                                                                          });
                                                                      }
                                                                      
                                                                      
                                                                      /**
                                                                      * @param {Object} obj
                                                                      * @param {string} obj.trackName
                                                                      * @param {'Enable'|'Disable'|'Toggle'} obj.openFolder
                                                                      * @param {'Mute'|'Unmute'|'Toggle'|''} obj.setMute
                                                                      */
                                                                      function folderSetOpenAndMuteState({ trackName, openFolder, setMute }) {
                                                                      
                                                                          const folderTrack = sf.ui.proTools.trackGetByName({ name: trackName }).track
                                                                      
                                                                          const isMuted = folderTrack.muteButton.value.invalidate().value === "on state"
                                                                      
                                                                      
                                                                          // If track size smaller than small, change to small
                                                                          if (folderTrack.frame.h < 43) {
                                                                              folderTrack.trackSelect()
                                                                              folderTrack.trackScrollToView()
                                                                              setTrackSize('small')
                                                                              sf.ui.proTools.invalidate()
                                                                          }
                                                                      
                                                                          //  Open or Close folder
                                                                          folderTrack.folderTrackSetOpen({ targetValue: openFolder });
                                                                      
                                                                          //  Mute, Unmute folder
                                                                          if (setMute === "Mute") {
                                                                              if (!isMuted) {
                                                                      
                                                                                  folderTrack.muteButton.elementClick()
                                                                              }
                                                                          } else if (setMute === "Unmute") {
                                                                              if (isMuted) {
                                                                      
                                                                                  folderTrack.muteButton.elementClick()
                                                                              }
                                                                          } else if (setMute === "Toggle") {
                                                                              folderTrack.muteButton.elementClick()
                                                                          }
                                                                      
                                                                      }
                                                                      
                                                                      
                                                                      ///  Set settings here
                                                                      folderSetOpenAndMuteState({
                                                                          trackName: "Folder Track Name",   //  Folder track name for action
                                                                          openFolder: "Enable",             // Enable or Disable or Toggle to open, close or toggle folder
                                                                          setMute: "Mute"                   // Mute, Unmute or Toggle Folder track
                                                                      })
                                                                      
                                                                      
                                                                      
                                                                      
                                                                      
                                                                      1. PPhilip weinrobe @Philip_weinrobe
                                                                          2022-01-17 16:42:35.868Z

                                                                          Hi Samuel!
                                                                          Brilliant script. is there a way we can modify to make it work for ALL FOLDERS in a session?

                                                                          1. samuel henriques @samuel_henriques
                                                                              2022-01-17 16:50:51.274Z

                                                                              Hello Philip,
                                                                              Are you looking for this specific actions, or you are looking for a general open/close all folders in a session?

                                                                              1. In reply toPhilip_weinrobe:
                                                                                samuel henriques @samuel_henriques
                                                                                  2022-01-17 17:00:35.382Z

                                                                                  This is my latest open/close all folders in a session.

                                                                                  normal trigger will close all, add ALT and it will open all

                                                                                  CAN'T have any folder track name using a "-" on the name!!!!

                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  
                                                                                  
                                                                                  
                                                                                  function closeAllFolderTracks(openFolders) {
                                                                                  
                                                                                    const folderTracksReverse = openFolders
                                                                                      .filter(track =>
                                                                                        track.title.invalidate().value.endsWith(' Folder Track ') && // This one is not needed, but makes it mutch faster
                                                                                        track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is("Close Folder").first.exists)
                                                                                      .map(folder => folder.normalizedTrackName)
                                                                                      .reverse()
                                                                                  
                                                                                    for (var i = 0; i < folderTracksReverse.length; i++) {
                                                                                  
                                                                                      sf.ui.proTools.trackGetByName({ name: folderTracksReverse[i] }).track.folderTrackSetOpen({
                                                                                        targetValue: 'Disable',
                                                                                      });
                                                                                  
                                                                                    };
                                                                                  
                                                                                    // Select visible folders
                                                                                    sf.ui.proTools.invalidate().trackSelectByName({ names: folderTracksReverse })
                                                                                  };
                                                                                  
                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  
                                                                                  function ensureOneSelectedTrack() {
                                                                                    const firstSelected = sf.ui.proTools.selectedTrackHeaders[0]
                                                                                    const viewSelectorPos = sf.ui.proTools.mainWindow.buttons.whoseTitle.is("Edit Window View selector").first.frame.y + 14
                                                                                    const trackListBtnPos = sf.ui.proTools.mainWindow.buttons.whoseTitle.is("Track List Show/Hide").first.frame.y
                                                                                    let firstTrackInView = sf.ui.proTools.visibleTrackHeaders.filter(track =>
                                                                                      track.frame.y > viewSelectorPos &&
                                                                                      track.frame.y < trackListBtnPos)[0]
                                                                                  
                                                                                    if (firstSelected) {
                                                                                      firstSelected.trackScrollToView()
                                                                                    } else {
                                                                                      firstTrackInView.trackSelect()
                                                                                      firstTrackInView.trackScrollToView()
                                                                                    }
                                                                                  }
                                                                                  
                                                                                  
                                                                                  const checkFolders = (/** @type {'Close Folder'|'Open Folder'} */ state) =>
                                                                                    sf.ui.proTools.visibleTrackHeaders.filter(track => track.children.whoseRole.is("AXDisclosureTriangle")
                                                                                      .whoseTitle.is(state).first.exists);
                                                                                  
                                                                                  
                                                                                  
                                                                                  let failed = []
                                                                                  function openAllFolderTracks() {
                                                                                    // Make sure there is one selected track, and header in sight
                                                                                    ensureOneSelectedTrack()
                                                                                  
                                                                                    // Open Folders
                                                                                    function open(folderTracks) {
                                                                                      if (folderTracks) {
                                                                                        folderTracks.forEach(folder => {
                                                                                          try {
                                                                                  
                                                                                            const folderTrack = sf.ui.proTools.trackGetByName({ name: folder }).track
                                                                                            if (folderTrack.frame.h < 43) {
                                                                                              folderTrack.trackSelect()
                                                                                              folderTrack.trackScrollToView()
                                                                                              setTrackSize('small')
                                                                                              sf.ui.proTools.invalidate()
                                                                                            }
                                                                                  
                                                                                            folderTrack.folderTrackSetOpen({ targetValue: "Enable" });
                                                                                          } catch (err) {
                                                                                            try {
                                                                                              sf.ui.proTools.trackGetByName({
                                                                                                name: sf.ui.proTools.visibleTrackNames.filter(x => x.includes(folder))[0]
                                                                                              }).track.folderTrackSetOpen({ targetValue: "Enable" });
                                                                                            } catch (e) { failed.push(folder) }
                                                                                          }
                                                                                        });
                                                                                        sf.ui.proTools.invalidate()
                                                                                      }
                                                                                    };
                                                                                  
                                                                                    const [m1, m2, ...folderMenu] = sf.ui.proTools.selectedTrack.popupButtons.first.popupMenuFetchAllItems({ isRightClick: true })
                                                                                      .menuItems.filter(item =>
                                                                                        item.path[0] === "Move to..."
                                                                                      ).map(m => m.path[1])
                                                                                    sf.ui.proTools.appActivateMainWindow()
                                                                                  
                                                                                    //array for each level
                                                                                    let folderArr = [[], [], [], [], [], [], [], []]
                                                                                    folderMenu.map(menu => {
                                                                                      if (!menu.startsWith(" -")) { folderArr[0].push(menu) }
                                                                                      else if (menu.startsWith(" -------")) { folderArr[7].push(menu.split(" -------")[1].trim()) }
                                                                                      else if (menu.startsWith(" ------")) { folderArr[6].push(menu.split(" ------")[1].trim()) }
                                                                                      else if (menu.startsWith(" -----")) { folderArr[5].push(menu.split(" -----")[1].trim()) }
                                                                                      else if (menu.startsWith(" ----")) { folderArr[4].push(menu.split("----")[1].trim()) }
                                                                                      else if (menu.startsWith(" ---")) { folderArr[3].push(menu.split(" ---")[1].trim()) }
                                                                                      else if (menu.startsWith(" --")) { folderArr[2].push(menu.split(" --")[1].trim()) }
                                                                                      else if (menu.startsWith(" -")) { folderArr[1].push(menu.split(" -")[1].trim()) }
                                                                                    })
                                                                                  
                                                                                    //  For each folder parent/level, function open() will receive a array of folders
                                                                                    folderArr.forEach(folderTracks =>
                                                                                      open(folderTracks)
                                                                                    )
                                                                                  
                                                                                  
                                                                                    //  Double check if all folders are open
                                                                                    let closedFolders = checkFolders("Open Folder")
                                                                                  
                                                                                    if (closedFolders.length > 0) {
                                                                                      open(closedFolders.map(folder => folder.normalizedTrackName))
                                                                                    }
                                                                                  
                                                                                    // Select visible folders
                                                                                    sf.ui.proTools.trackSelectByName({ names: [].concat([], ...folderArr) })
                                                                                  
                                                                                  }
                                                                                  
                                                                                  /**
                                                                                  * @param {string} job
                                                                                  */
                                                                                  function finishedTheJob(job) {
                                                                                    sf.interaction.displayDialog({
                                                                                      prompt: job,
                                                                                      giveUpAfterSeconds: 1
                                                                                    });
                                                                                  };
                                                                                  
                                                                                  
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  
                                                                                  function setTrackSize(size) {
                                                                                  
                                                                                    const f = sf.ui.proTools.selectedTrack.frame;
                                                                                    const popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                                                                                      relativePosition: { x: f.w - 10, y: 5 },
                                                                                      isOption: true,
                                                                                      isShift: true,
                                                                                    }).popupMenu;
                                                                                    popupMenu.menuClickPopupMenu({
                                                                                      menuPath: [size]
                                                                                    });
                                                                                  }
                                                                                  
                                                                                  
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                  
                                                                                  
                                                                                  function main() {
                                                                                  
                                                                                    const hasAlt = event.keyboardState.hasAlt
                                                                                  
                                                                                    sf.ui.proTools.appActivateMainWindow();
                                                                                    sf.ui.proTools.invalidate();
                                                                                  
                                                                                  
                                                                                    // Check if Track List is Open
                                                                                    const isTrackListOpen = () => sf.ui.proTools.getMenuItem('View', 'Other Displays', 'Track List').isMenuChecked
                                                                                  
                                                                                    const initialState = isTrackListOpen()
                                                                                  
                                                                                    // // Open Track List
                                                                                    sf.ui.proTools.menuClick({ menuPath: ['View', 'Other Displays', 'Track List'], targetValue: "Enable" })
                                                                                  
                                                                                  
                                                                                  
                                                                                    if (hasAlt) {
                                                                                  
                                                                                      openAllFolderTracks()
                                                                                  
                                                                                      if (failed.length > 0) {
                                                                                        alert("Could not open folder: \n\n" + failed.join("\n"))
                                                                                      } else {
                                                                                        finishedTheJob("All Folder Tracks are Open.")
                                                                                      }
                                                                                  
                                                                                  
                                                                                    } else {
                                                                                  
                                                                                  
                                                                                      if (checkFolders("Close Folder").length > 0) {
                                                                                  
                                                                                        closeAllFolderTracks(checkFolders("Close Folder"))
                                                                                  
                                                                                      }
                                                                                  
                                                                                      finishedTheJob("All Folder Tracks are Closed.")
                                                                                    };
                                                                                  
                                                                                  
                                                                                    // Set Track List to Initial State
                                                                                    if (initialState != isTrackListOpen()) {
                                                                                      sf.ui.proTools.menuClick({ menuPath: ['View', 'Other Displays', 'Track List'], targetValue: "Disable" })
                                                                                    };
                                                                                  
                                                                                  };
                                                                                  
                                                                                  main()
                                                                                  
                                                                                  
                                                                                  
                                                                                  1. PPhilip weinrobe @Philip_weinrobe
                                                                                      2022-01-17 17:18:10.075Z

                                                                                      hmmm, this script is throwing errors for me. says it can't open one of my folders. I don't have any '-' characters.
                                                                                      is it possible to get the other more simple script modified so that it just works on all folders?

                                                                                      what i'm trying to do:
                                                                                      have a simple script that can open all top level folders (don't care about sub-folders) with a key command. then i can duplicate that script and change parameters so that it closes all top level folders. both these actions would be regardless of current open/close state of folder.

                                                                                      the previous script i replied to did that well, except it was written to have other stuff i didn't need that was getting in the way (track name, mute, etc)

                                                                                      1. Ben Rubin @Ben_Rubin
                                                                                          2022-03-10 03:57:54.067Z

                                                                                          Hey @samuel_henriques,

                                                                                          Thanks for the great script! It runs natively on the mix window to close all folders, but it will only open all folders (via the alt modifier) in the edit window. is it possible to make it open all folders natively in the mix window as well?

                                                                                          thanks
                                                                                          ben

                                                                                          1. This was working GREAT for a day and I was using it A LOT, but then all the next day it didn't work. It's giving me this error

                                                                                            11.03.2022 14:47:42.07 [Backend]: !! Command Error: CLOSE ALL FOLDERS SAM [user:ckrzha59p0002b4109dgubkd8:cl0kksdf600004d10ys117ga4]:
                                                                                            Folder Open/Close state didn't update (CLOSE ALL FOLDERS SAM: Line 17

                                                                                            Restarted SF and ProTools, no dice. Any thoughts? Of note the session HUUUUUGE.

                                                                                            1. samuel henriques @samuel_henriques
                                                                                                2022-03-11 22:56:35.547Z

                                                                                                Hello Owen,

                                                                                                I'm sorry everyone I've been unable to concentrate on the forum for some days but it'll be better soon.

                                                                                                To answer your question, I thing it might happen if the folder tracks size is smaller than small, I think I've come up with a fix for this problem working on another script, but I'll need some time to be able to add it to this script.

                                                                                                Hope this helps.

                                                                                                1. That did the trick thanks!

                                                                                          2. CCooper Babbes @cooper
                                                                                              2022-02-26 00:15:49.651Z

                                                                                              Sorry for such a late reply here. This works perfectly, thanks a ton for this!

                                                                                              1. samuel henriques @samuel_henriques
                                                                                                  2022-08-22 14:17:51.747Z

                                                                                                  For anyone coming across this, her's my latest open/close all folder tracks.
                                                                                                  Much faster and less scripting.

                                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  function closeAllFolderTracks(openFolders) {
                                                                                                  
                                                                                                    const folderTracksReverse = openFolders
                                                                                                      .filter(track =>
                                                                                                        track.title.invalidate().value.endsWith(' Folder Track ') && // This one is not needed, but makes it mutch faster
                                                                                                        track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is("Close Folder").first.exists)
                                                                                                      .map(folder => folder.normalizedTrackName)
                                                                                                      .reverse()
                                                                                                  
                                                                                                    for (var i = 0; i < folderTracksReverse.length; i++) {
                                                                                                  
                                                                                                      sf.ui.proTools.trackGetByName({ name: folderTracksReverse[i] }).track.folderTrackSetOpen({
                                                                                                        targetValue: 'Disable',
                                                                                                      });
                                                                                                  
                                                                                                    };
                                                                                                  
                                                                                                    // Select visible folders
                                                                                                    //sf.ui.proTools.invalidate().trackSelectByName({ names: folderTracksReverse })
                                                                                                  };
                                                                                                  
                                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  function openAll() {
                                                                                                    sf.ui.proTools.groupsEnsureGroupListIsVisible();
                                                                                                    sf.ui.proTools.mainWindow.groupListView.children.whoseRole.is("AXColumn").first
                                                                                                      .children.whoseRole.is("AXRow").first
                                                                                                      .children.whoseRole.is("AXCell").first
                                                                                                      .buttons.first.elementClick();
                                                                                                  
                                                                                                    sf.ui.proTools.trackDeselectAll();
                                                                                                  };
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  function openAllFolderTracks() {
                                                                                                    sf.ui.proTools.invalidate()
                                                                                                  
                                                                                                    const selectedTrackHeaders = sf.ui.proTools.selectedTrackHeaders;
                                                                                                  
                                                                                                    openAll();
                                                                                                  
                                                                                                    sf.ui.proTools.invalidate();
                                                                                                  
                                                                                                  
                                                                                                    // Select original Track Selection
                                                                                                    if (selectedTrackHeaders.length > 0) {
                                                                                                      selectedTrackHeaders[0].trackSelect()
                                                                                                      selectedTrackHeaders[0].trackScrollToView()
                                                                                                      sf.ui.proTools.trackSelectByName({ names: selectedTrackHeaders.map(tr => tr.normalizedTrackName) })
                                                                                                    };
                                                                                                  };
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                  /**
                                                                                                  * @param {string} job
                                                                                                  */
                                                                                                  function finishedTheJob(job) {
                                                                                                    sf.interaction.displayDialog({
                                                                                                      prompt: job,
                                                                                                      giveUpAfterSeconds: 1
                                                                                                    });
                                                                                                  };
                                                                                                  
                                                                                                  const checkFolders = (/** @type {'Close Folder'|'Open Folder'} */ state) =>
                                                                                                    sf.ui.proTools.visibleTrackHeaders.filter(track => track.children.whoseRole.is("AXDisclosureTriangle")
                                                                                                      .whoseTitle.is(state).first.exists);
                                                                                                  
                                                                                                  
                                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                                                                  
                                                                                                  
                                                                                                  function main() {
                                                                                                  
                                                                                                    const hasAlt = event.keyboardState.hasAlt
                                                                                                  
                                                                                                    sf.ui.proTools.appActivateMainWindow();
                                                                                                    sf.ui.proTools.invalidate();
                                                                                                  
                                                                                                  
                                                                                                    // Check if Track List is Open
                                                                                                    const isTrackListOpen = () => sf.ui.proTools.getMenuItem('View', 'Other Displays', 'Track List').isMenuChecked
                                                                                                  
                                                                                                    const initialState = isTrackListOpen()
                                                                                                  
                                                                                                    // // Open Track List
                                                                                                    sf.ui.proTools.menuClick({ menuPath: ['View', 'Other Displays', 'Track List'], targetValue: "Enable" })
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                    if (hasAlt) {
                                                                                                  
                                                                                                      openAllFolderTracks()
                                                                                                  
                                                                                                  
                                                                                                      finishedTheJob("All Folder Tracks are Open.")
                                                                                                  
                                                                                                  
                                                                                                  
                                                                                                    } else {
                                                                                                  
                                                                                                  
                                                                                                      if (checkFolders("Close Folder").length > 0) {
                                                                                                  
                                                                                                        closeAllFolderTracks(checkFolders("Close Folder"))
                                                                                                  
                                                                                                      }
                                                                                                  
                                                                                                      finishedTheJob("All Folder Tracks are Closed.")
                                                                                                    };
                                                                                                  
                                                                                                  
                                                                                                    // Set Track List to Initial State
                                                                                                    if (initialState != isTrackListOpen()) {
                                                                                                      sf.ui.proTools.menuClick({ menuPath: ['View', 'Other Displays', 'Track List'], targetValue: "Disable" })
                                                                                                    };
                                                                                                  
                                                                                                  };
                                                                                                  
                                                                                                  main()