No internet connection
  1. Home
  2. How to

Script for Select Unused Clips + Remove Selected Clips

By Victor Amaral @Victor_Amaral
    2021-04-07 00:00:08.971Z

    Hello Guys!

    Im trying to create a script for select the unused clips from the clip list and then remove then (Command+Shift+U and Command+Shift+B).

    But I didnt find nothing like it in the forum.

    Could you guys help me out?

    Thanks!

    • 18 replies

    There are 18 replies. Estimated reading time: 12 minutes

    1. Dustin Harris @Dustin_Harris
        2021-04-07 02:12:49.306Z

        I have this very script as part of a larger one that I can post next timid I’m at my computer, but I’m sure someone else can beat me to it. Nudge me in 12hrs if no one else replies :)

        1. SSøren Valur @Szren_Valur
            2024-12-02 22:27:35.845Z

            Hi Dustin, i couldent seem to make Samuels script work. Do you think you could send me your version of such script? :)

          • In reply toVictor_Amaral:
            samuel henriques @samuel_henriques
              2021-04-07 09:32:38.304Z2021-04-10 14:54:03.789Z

              Hello @Victor_Amaral,

              I too had most of this in other scripts.

              Let the know if it works for you.

              
              
              function clearConfirmationDialog(button) {
                  if (sf.ui.proTools.confirmationDialog.invalidate().buttons.whoseTitle.is(button).first.exists) {
                      sf.keyboard.modifiers({ isOption: true })
                      sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is(button).first.elementClick();
                  }
              }
              
              
              function clipListEnableMenu(path) {
                  sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is('Clip List').first.popupMenuSelect({
                      menuPath: path, targetValue: "Enable"
                  });
              }
              
              
              function clipListEnableSubmenu({ menu, subMenu }) {
                  const menuCheckedInShowMenu = sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is('Clip List').first.popupMenuFetchAllItems().menuItems.filter(x =>
                      !x.element.isMenuChecked && //  Not MenuChecked
                      x.path[0] == menu).map(x => x.path[1]) // index 1 only from submenu Show
                  sf.ui.proTools.appActivateMainWindow()
              
                  let menuToCheck = menuCheckedInShowMenu.filter(x => subMenu.includes(x)).map(x => [menu, x])
                  menuToCheck.forEach(clipListEnableMenu)
              }
              
              
              //====================================
              
              
              //  Activate Pt
              sf.ui.proTools.appActivateMainWindow()
              
              // Make sure Clip List is Visible
              sf.ui.proTools.menuClick({ menuPath: ["View", "Other Displays", "Clip List"], targetValue: "Enable" });
              
              clipListEnableMenu(["Clear Find"])
              
              //  Enable SubMenus
              clipListEnableSubmenu({
                  menu: "Show",
              
                  subMenu: [
                      "Audio",
                      "MIDI",
                      "Video",
                      "Groups",
                      "Auto-Created",
                  ]
              })
              
              clipListEnableMenu(["Select", "Unused"])
              
              
              const clipsTable = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first;
              const selectedClips = clipsTable.getElements("AXSelectedRows")
              const selectedClipCount = selectedClips.allItems.length;
              
              
              if (selectedClipCount >= 1) {
              
                  clipListEnableMenu(["Clear..."])
              
                 
                  //clearConfirmationDialog('Remove')  // click Remove on confirmation dialog
              
              } else {
                  alert("No Unused Clips.")
              }
              
              1. samuel henriques @samuel_henriques
                  2021-04-07 11:19:14.996Z

                  UPDATE: cleaned a bit the code, but should work the same way

                  1. samuel henriques @samuel_henriques
                      2021-04-07 17:39:07.112Z

                      UPDATE: now it will enable from view menu, only the menus that are not yet enabled. This avoids going to the menu 5 times if they are already enabled.

                  2. V
                    In reply toVictor_Amaral:
                    Victor Amaral @Victor_Amaral
                      2021-04-09 19:49:47.027Z

                      Thank you so much for the support, guys! I'll try and see if it works!

                      1. samuel henriques @samuel_henriques
                          2021-04-10 14:49:44.448Z

                          Hello guys,

                          I'VE FOUND AN ERROR WITH THE SCRIPT. I've always been afraid of doing this process with a script, as I feel it gives me time to think if I'm fu***** up. But since I did it for @Victor_Amaral, I started using it, but instead of remove unused, I use it to delete unused.

                          Most sessions, I had no problem, but in some sessions, it would not select the first selected clip but another one usually (if no always) not unused. Since the script will dismiss the next confirmation dialog, BIG POO!!

                          I've updated above the fix for this and kept the dismiss as comment, USE CAREFULLY PLEASE.
                          Instead of using "Clear..." on the selected clip + right click popup, it uses the clip list menu (it's way more stable, and won't cause the same mistake, sorry I didn't think about it before)

                          I'm going to keep using it, but will manually dismiss the dialog for now.

                          1. Hi @samuel_henriques
                            Just seeing this script and it works well. I'm wondering how to tweak it so that it automatically selects "Delete" and the "OK" on all the subsequent popups that try to confirm that you want to delete this track?

                            For big sessions that's a lot of clicking :-) Thanks!

                            PS oh and not sure but does this also delete unused playlists?

                            1. Comment deleted
                              1. Thank you! I will report back!!

                                1. Hey again @samuel_henriques
                                  Ok so I tried this newest script you posted above.
                                  I'm a little confused. It's prompting me with this.

                                  I just want this delete all unused clips. It this asking if I want to delete ALL, include "in use"?

                                  1. samuel henriques @samuel_henriques
                                      2022-01-24 23:31:42.276Z

                                      Hello Brett,
                                      My mistake, I'm sorry. I deleted the post in case someone comes across this.

                                      To dismiss the confirmation just un-comment this line in the original script:

                                      clearConfirmationDialog('Remove')  // click Remove on confirmation dialog
                                      

                                      If you want to click "Delete" instead of "Remove" use:

                                      clearConfirmationDialog('Delete')  // click Delete on confirmation dialog
                                      
                                      

                                      About the playlists. Would you like to click "Delete Unused..." and select all available from the window?

                                      1. Thanks @samuel_henriques ! That seems to have done it.
                                        When you say "un-comment" do you just mean delete that line?

                                        Either way I swapped the remove line out for delete and it seems to have taken care of it.
                                        For the playlist delete, yes that would be great! Maybe as a separate command though?

                                        1. samuel henriques @samuel_henriques
                                            2022-01-29 22:15:25.710Z

                                            Here you go Brett,

                                            /**
                                            * @param {string} trackType - All track types included on trackTypes array
                                            */
                                            function deleteUnusedPlaylists(trackType) {
                                            
                                                // Check if there are any tracks of trackType
                                                const trackTypeExists = sf.ui.proTools.visibleTrackHeaders.some(x => x.title.invalidate().value.includes(trackType))
                                            
                                                if (trackTypeExists) {
                                            
                                                    // Get name of first track of trackType
                                                    const firstTrackByTypeName = sf.ui.proTools.visibleTrackHeaders.filter(x => x.title.invalidate().value.includes(trackType))[0].normalizedTrackName
                                            
                                                    // Find track by name
                                                    const getFirstTrackByTypeName = sf.ui.proTools.trackGetByName({ name: firstTrackByTypeName }).track
                                            
                                                    // Scrool track if needed
                                                    getFirstTrackByTypeName.trackScrollToView()
                                            
                                                    // Delete unused menu
                                                    getFirstTrackByTypeName.popupButtons.whoseTitle.is("Playlist selector").first.popupMenuSelect({ menuPath: ["Delete Unused..."] });
                                            
                                                    // Delete unused window
                                                    const deleteUnusedWin = sf.ui.proTools.windows.whoseTitle.is("Delete Unused Playlists").first
                                            
                                                    if (deleteUnusedWin.exists) {
                                                        const deleteUnusedWinTable = deleteUnusedWin.tables.first.children.whoseRole.is("AXRow")
                                            
                                                        // Select all unused playlists
                                                        deleteUnusedWinTable.map(x => x.children.first.children.whoseRole.is("AXStaticText").first.elementClick())
                                            
                                                        // Click delete Btn
                                                        deleteUnusedWin.buttons.whoseTitle.is("Delete").first.elementClick();
                                                    };
                                                };
                                            };
                                            
                                            
                                            
                                            
                                            function main() {
                                            
                                                sf.ui.proTools.appActivateMainWindow();
                                            
                                                //  delete unused playlists, needs to be done on all track types
                                                const trackTypes = [
                                                    "Video Track",
                                                    "MIDI Track",
                                                    "Inst Track",
                                                    "Audio Track"
                                                ]
                                            
                                                trackTypes.forEach(deleteUnusedPlaylists)
                                            
                                            }
                                            
                                            
                                            main()
                                            
                                            1. Hero! Works great thanks @samuel_henriques !!

                                              1. samuel henriques @samuel_henriques
                                                  2022-01-29 23:23:51.829Z

                                                  Awesome, glad to help.

                                2. In reply toVictor_Amaral:
                                  Donny @Dreamcatcher_Studio
                                    2024-02-21 20:42:42.883Z

                                    @Kitch , this is the script I was referencing last week at our hangout. For some reason I can't get the ui element in the clipListEnableMenu function on line 11. I think it's that little drop down arrow thingy.

                                    1. samuel henriques @samuel_henriques
                                        2024-02-22 18:23:13.192Z

                                        Hello Dreamcatcher_Studio,
                                        Is the clip list closed?
                                        Do you get an error and the script fails?

                                        1. Donny @Dreamcatcher_Studio
                                            2024-03-10 02:48:41.174Z

                                            Thanks for the reply! The script works :)
                                            I was having some user error ridding of unused clips in something else I was working on.
                                            I brought this up in the Soundflow Zoom hang, so I just tagged Kitch here. I wasn't able to get the UI element, but I don't think it matters anymore.
                                            Thanks again for your support.