No internet connection
  1. Home
  2. Support

Closing all FOLDER tracks in Pro Tools

By @Ugosound
    2020-06-04 23:04:40.335Z

    Hi!

    Is there a way to create a shortcut to quickly close all FOLDER tracks in Pro Tools?

    When working on session with a huge number of tracks, it's alway a bit of a pain to scroll down and up to find the folder track., etc... If I could close all that are opened, it would be super fast then to open a specific one without to have to scroll at all.

    Solved in post #5, click to view
    • 16 replies

    There are 16 replies. Estimated reading time: 19 minutes

    1. In reply toUgosound:
      Dustin Harris @Dustin_Harris
        2020-06-06 15:57:38.507Z2020-06-06 19:50:21.470Z

        Try this. I think I figured out the select-all business.

        
        function selectAllTracks() {
            var trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[0].header;
            trackHeader.trackSelect();
            trackHeader.trackScrollToView();
            sf.ui.proTools.trackDeselectAll();
            sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.mouseClickElement({ isOption: true });
        }
        
        function getFolders(name, index) {
            var trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[index].header;
            var button = trackHeader.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first;
            if (button.exists) {
                openFolders.push(name);
            }
        }
        
        function closeFolders(name, index) {
            sf.ui.proTools.mainWindow.invalidate();
            sf.ui.proTools.trackSelectByName({
                deselectOthers: true,
                names: [name]
            });
        
            if (sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.exists) {
                sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.elementClick();
            }
        }
        
        
        sf.ui.proTools.appActivateMainWindow();
        
        var openFolders = [];
        
        selectAllTracks();
        
        var selectedTracks = sf.ui.proTools.selectedTrackNames;
        
        
        
        selectedTracks.forEach(getFolders);
        
        openFolders.forEach(closeFolders);
        
        1. In reply toUgosound:
          Dustin Harris @Dustin_Harris
            2020-06-06 18:19:24.051Z

            Updated original post.

            1. In reply toUgosound:
              Dustin Harris @Dustin_Harris
                2020-06-06 22:14:54.038Z

                This actually might be a faster way to accomplish it. It option-clicks the first open folder track it finds:

                function selectAllTracks() {
                    var trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[0].header;
                    trackHeader.trackSelect();
                    trackHeader.trackScrollToView();
                    sf.ui.proTools.trackDeselectAll();
                    sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.mouseClickElement({ isOption: true });
                }
                
                sf.ui.proTools.appActivateMainWindow();
                
                sf.ui.proTools.mainWindow.invalidate();
                
                selectAllTracks();
                
                var selectedTracks = sf.ui.proTools.selectedTrackNames;
                
                for (var i = 0; i < selectedTracks.length; i++) {
                    sf.ui.proTools.trackSelectByName({
                        deselectOthers: true,
                        names: [selectedTracks[i]]
                    });
                
                    if (sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.exists) {
                        sf.ui.proTools.selectedTrack.trackScrollToView();
                        sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").first.mouseClickElement({
                            isOption: true,
                        });
                        break;
                    }
                
                }
                
                ReplySolution
                1. Dustin Harris @Dustin_Harris
                    2020-06-06 22:31:51.192Z

                    There still seems to be issues with the selectAllTracks logic. It works if the first track in the session is a folder, but not another type of track. Hmmmm

                  • U
                    In reply toUgosound:
                    @Ugosound
                      2020-06-07 17:58:18.415Z

                      Really cool. Thanks Dustin!!!

                      Last scripts works, per your note, I just needed to create folder at the top of my session where I usually have the QTs and QT Audio anyway, so I just placed all of those into a "Media" Basic Folder and it totally works. Amazing!

                      1. Dustin Harris @Dustin_Harris
                          2020-06-09 19:43:56.020Z

                          I'm going to come back to this and refine it a bunch. I just figured out another problem with it: it won't work if the tracks are small enough to hide the folder button, and I'll try and fix the track logic so it doesn't need to be a folder track at the top first :)

                          1. In reply toUgosound:
                            Dustin Harris @Dustin_Harris
                              2020-06-10 02:25:19.516Z

                              OK here's something. I think I've made the select all tracks a bit more reliable (no longer need a folder track at the top of the session?) and to speed things up, this track specifically looks for he name folder in the track name of all folder tracks (aka you must have the word 'folder' in your folder track names) and then only selects those tracks to try and collapse. Checking for the button on all tracks took too long when the first say, 50 tracks weren't folders. Maybe this is good organizationally in the long run? (time will tell :) )
                              (EDIT: I made it so it restores the track selection when it's finished)

                              function selectAllTracks() {
                                  var trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[0].header;
                                  trackHeader.trackSelect();
                                  trackHeader.trackScrollToView();
                                  sf.ui.proTools.trackDeselectAll();
                                  if (sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.exists) {
                                      sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.mouseClickElement({ isOption: true });
                                  } else if (sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.exists) {
                                      sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.mouseClickElement({ isOption: true });
                                  } else {
                                      alert(`Couldn't select all tracks for some reason`)
                                      throw 0;
                                  }
                              
                              }
                              
                              //this function here is all Christian. He's literally the best.
                              function trackSize() {
                              
                                  var size = 'small';
                              
                                  var f = sf.ui.proTools.selectedTrack.frame;
                                  var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                                      relativePosition: { x: f.w - 10, y: 5 },
                                      isOption: true,
                                      isShift: true,
                                  }).popupMenu;
                                  popupMenu.menuClickPopupMenu({
                                      menuPath: [size]
                                  });
                              
                              }
                              
                              sf.ui.proTools.appActivateMainWindow();
                              
                              sf.ui.proTools.mainWindow.invalidate();
                              
                              var originalSelection = sf.ui.proTools.selectedTrackNames;
                              
                              selectAllTracks();
                              
                              var selectedTracks = sf.ui.proTools.selectedTrackNames;
                              
                              var folderTracks = selectedTracks.filter(n => n.match(/Folder/i))
                              
                              trackSize();
                              
                              for (var i = 0; i < folderTracks.length; i++) {
                                  sf.ui.proTools.trackSelectByName({
                                      deselectOthers: true,
                                      names: [folderTracks[i]]
                                  });
                              
                                  if (sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.exists) {
                                      sf.ui.proTools.selectedTrack.trackScrollToView();
                                      sf.ui.proTools.selectedTrack.children.whoseRole.is("AXDisclosureTriangle").first.mouseClickElement({
                                          isOption: true,
                                      });
                                      break;
                                  }
                              
                              }
                              
                              sf.ui.proTools.trackSelectByName({
                                  deselectOthers: true,
                                  names: originalSelection
                              });
                              
                              
                              1. MMax Hartstang @Max_Hartstang4
                                  2021-06-01 22:59:07.112Z

                                  Hey there,

                                  I just can not get this Script running. It keeps giving me the error:

                                  02.06.2021 00:58:34.50 [Backend]: !! Command Error: Close all Folders [user:ck8aqo294001ok4106fybvj77:ckpem36uv0000uu106biiq2lb]:
                                  No track selected (in Track List View)
                                  Consider turning on Link Edit and Track Selection (Close all Folders: Line 22)

                                  I have Link Edit and Track Selection turned on and it actually is selecting all tracks despite the error saying no track selected...
                                  Can you help me out?

                                  Best

                                  1. Dustin Harris @Dustin_Harris
                                      2021-06-02 03:41:54.378Z

                                      I’ll have a look in the morning :) it’s relatively old code for me so I’m sure I can improve it a bit.

                                      1. In reply toMax_Hartstang4:
                                        Dustin Harris @Dustin_Harris
                                          2021-06-02 13:03:18.193Z2021-06-06 19:46:46.101Z

                                          Hi Max!

                                          Try this:

                                          
                                          function selectAllTracks() {
                                          
                                              let trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[0].header;
                                              trackHeader.trackSelect();
                                              trackHeader.trackScrollToView();
                                              sf.ui.proTools.trackDeselectAll();
                                          
                                              if (sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.exists) {
                                                  sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.mouseClickElement({ isOption: true });
                                              } else if (sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.exists) {
                                                  sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.mouseClickElement({ isOption: true });
                                              } else {
                                                  alert(`Could not select all tracks for some reason`)
                                                  throw 0;
                                              }
                                          
                                          }
                                          
                                          
                                          /**
                                          * @param {("micro" | "mini" | "small" | "medium" | "large" | "jumbo" | "extreme" | "fit to window")} trackHeight
                                          */
                                          function setTrackSize(trackHeight) {
                                          
                                              let frame = sf.ui.proTools.selectedTrack.frame;
                                              let popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                                                  relativePosition: { x: frame.w - 10, y: 5 },
                                                  isOption: true,
                                                  isShift: true,
                                              }).popupMenu;
                                              popupMenu.menuClickPopupMenu({
                                                  menuPath: [trackHeight]
                                              });
                                          
                                          }
                                          
                                          
                                          /**
                                          * @param {AxPtTrackHeader[]} folderTracks
                                          */
                                          function closeAllFolders(folderTracks) {
                                              folderTracks[0].trackScrollToView();
                                              folderTracks[0].children.whoseRole.is("AXDisclosureTriangle").first.mouseClickElement({
                                                  isOption: true,
                                              });
                                          }
                                          
                                          
                                          
                                          function main() {
                                          
                                              sf.ui.proTools.appActivateMainWindow()
                                              sf.ui.proTools.mainWindow.invalidate()
                                          
                                              let originalSelection = sf.ui.proTools.selectedTrackNames;
                                          
                                              sf.ui.proTools.trackEnsureTrackListViewIsAccessible({ makeVisible: true })
                                          
                                              selectAllTracks();
                                          
                                              sf.wait({ intervalMs: 200 });
                                          
                                              if (sf.ui.proTools.selectedTracks.trackHeaders.filter(track => track.frame.h < 43).length > 0) {
                                                  setTrackSize("small");
                                              }
                                          
                                              let folderTracks = sf.ui.proTools.selectedTracks.trackHeaders.filter(track => track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.exists)
                                          
                                              if (folderTracks[0] === undefined) {
                                                  log('All Folders are Closed');
                                                  sf.ui.proTools.trackSelectByName({
                                                      deselectOthers: true,
                                                      names: originalSelection
                                                  }, `could not restore original track selection`);
                                                  throw 0;
                                              }
                                          
                                              closeAllFolders(folderTracks);
                                          
                                              sf.ui.proTools.trackSelectByName({
                                                  deselectOthers: true,
                                                  names: originalSelection
                                              }, `could not restore original track selection`);
                                              sf.ui.proTools.selectedTrack.trackScrollToView();
                                          }
                                          
                                          main();
                                          
                                          1. MMax Hartstang @Max_Hartstang4
                                              2021-06-06 18:36:46.370Z

                                              Hi Dustin,

                                              thank you very much! It's very kind of you to put all that work in!

                                              With your new code it works fine as long as I have a Folder on top of my session, what I always have anyway!
                                              Anyway it gives me this error after it closed all Folders: "Object reference not set to an instance of an object." I don't mind but I wanted to let you know!

                                              Thank you again!
                                              Cheers

                                              1. Dustin Harris @Dustin_Harris
                                                  2021-06-06 19:31:14.478Z

                                                  Thanks for the info; Yeah the script assumes there ARE open folders and I haven't set up error handling for that (I'll do that now)...
                                                  but what happens when you -don't- have a folder at the top of your session? (it works here without one at the top of my session...)

                                                  1. In reply toMax_Hartstang4:
                                                    Dustin Harris @Dustin_Harris
                                                      2021-06-06 19:47:23.166Z

                                                      I've updated the script above, let me know if it solves both problems :)

                                                      Thanks,
                                                      Dustin

                                                      1. marcello azevedo @marcello_azevedo
                                                          2021-06-25 16:28:50.378Z

                                                          Great script Thank you!!!
                                                          I've added "close tracklist" side window at the end, I never leave it open on my workflow:

                                                          function selectAllTracks() {
                                                          
                                                              let trackHeader = sf.ui.proTools.trackGetAllTracks().trackListItems[0].header;
                                                              trackHeader.trackSelect();
                                                              trackHeader.trackScrollToView();
                                                              sf.ui.proTools.trackDeselectAll();
                                                          
                                                              if (sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.exists) {
                                                                  sf.ui.proTools.mainWindow.groups.allItems[7].popupButtons.first.mouseClickElement({ isOption: true });
                                                              } else if (sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.exists) {
                                                                  sf.ui.proTools.trackListItems[0].children.allItems[1].buttons.first.mouseClickElement({ isOption: true });
                                                              } else {
                                                                  alert(`Could not select all tracks for some reason`)
                                                                  throw 0;
                                                              }
                                                          
                                                          }
                                                          
                                                          
                                                          /**
                                                          * @param {("micro" | "mini" | "small" | "medium" | "large" | "jumbo" | "extreme" | "fit to window")} trackHeight
                                                          */
                                                          function setTrackSize(trackHeight) {
                                                          
                                                              let frame = sf.ui.proTools.selectedTrack.frame;
                                                              let popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({
                                                                  relativePosition: { x: frame.w - 10, y: 5 },
                                                                  isOption: true,
                                                                  isShift: true,
                                                              }).popupMenu;
                                                              popupMenu.menuClickPopupMenu({
                                                                  menuPath: [trackHeight]
                                                              });
                                                          
                                                          }
                                                          
                                                          
                                                          /**
                                                          * @param {AxPtTrackHeader[]} folderTracks
                                                          */
                                                          function closeAllFolders(folderTracks) {
                                                              folderTracks[0].trackScrollToView();
                                                              folderTracks[0].children.whoseRole.is("AXDisclosureTriangle").first.mouseClickElement({
                                                                  isOption: true,
                                                              });
                                                          }
                                                          
                                                          
                                                          
                                                          function main() {
                                                          
                                                              sf.ui.proTools.appActivateMainWindow()
                                                              sf.ui.proTools.mainWindow.invalidate()
                                                          
                                                              let originalSelection = sf.ui.proTools.selectedTrackNames;
                                                          
                                                              sf.ui.proTools.trackEnsureTrackListViewIsAccessible({ makeVisible: true })
                                                          
                                                              selectAllTracks();
                                                          
                                                              sf.wait({ intervalMs: 200 });
                                                          
                                                              if (sf.ui.proTools.selectedTracks.trackHeaders.filter(track => track.frame.h < 43).length > 0) {
                                                                  setTrackSize("small");
                                                              }
                                                          
                                                              let folderTracks = sf.ui.proTools.selectedTracks.trackHeaders.filter(track => track.children.whoseRole.is("AXDisclosureTriangle").whoseTitle.is('Close Folder').first.exists)
                                                          
                                                              if (folderTracks[0] === undefined) {
                                                                  log('All Folders are Closed');
                                                                  sf.ui.proTools.trackSelectByName({
                                                                      deselectOthers: true,
                                                                      names: originalSelection
                                                                  }, `could not restore original track selection`);
                                                                  throw 0;
                                                              }
                                                          
                                                              closeAllFolders(folderTracks);
                                                          
                                                              sf.ui.proTools.trackSelectByName({
                                                                  deselectOthers: true,
                                                                  names: originalSelection
                                                              }, `could not restore original track selection`);
                                                              sf.ui.proTools.selectedTrack.trackScrollToView();
                                                          }
                                                          
                                                          main();
                                                          
                                                          sf.ui.proTools.menuClick({
                                                              menuPath: ["View", "Other Displays", "Track List"],
                                                          });
                                                          
                                                          
                                              2. In reply toUgosound:
                                                marcello azevedo @marcello_azevedo
                                                  2021-06-25 16:33:12.518Z

                                                  Is it possible to have it behave as "toggle"?
                                                  If any or all open, then close all, if any or all closed then open all.
                                                  Thanks in advance

                                                  1. R
                                                    In reply toUgosound:
                                                    Reid Caulfield @Reid_Caulfield
                                                      2021-08-27 18:49:24.143Z

                                                      This is interesting. Dustin's script above was working for me a month or so ago, but now it's throwing up this error after having successfully closed all folder tracks:

                                                      27.08.2021 11:45:07.79 [Backend]: Logging error in action (01) GetFirstSelectedTrackHeaderAction: No track selected (in Track List View)
                                                      No track selected (in Track List View)
                                                      27.08.2021 11:45:46.61 [Backend]: Logging error in action (01) GetFirstSelectedTrackHeaderAction: No track selected (in Track List View)
                                                      No track selected (in Track List View)

                                                      So it works, but now with this error at the end of the operation. Thoughts?