No internet connection
  1. Home
  2. Ideas
  3. Pro Tools

Pro Tools: remove all bypassed plug inns from session

By Jonathan Johnson @Jonathan_Johnson
    2025-09-16 19:41:40.249Z

    Pro Tools: remove all bypassed plug inns from session.

    • 4 replies
    1. C
      Collin Dupuis @Collin_Dupuis
        2025-10-28 18:22:58.694Z

        I would love this!

        1. Sreejesh Nair @Sreejesh_Nair
            2025-10-28 19:33:13.985Z

            @Jonathan_Johnson If you are looking to specfically remove bypassed plugins and inserts here is the code for that.

            if (sf.ui.useSfx && !globalState.OPP_disableSfx) sf.ui.useSfx();
            
            // Closes Pro Tools confirmation dialogs if they contain "Remove" or "Change" buttons
            function closeDialog() {
                ['Remove', 'Change'].forEach(title => {
                    const button = sf.ui.proTools.confirmationDialog.invalidate().buttons.whoseTitle.is(title).first;
                    if (button.exists) {
                        button.elementClick();
                        sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: "Disappear" });
                    }
                });
            }
            
            // Finds bypassed inserts and muted sends in the provided tracks and maps them
            function findBypassedItems(tracks) {
                let map = { inserts: {}, sends: {} };
                let elements = { inserts: [], sends: [] };
                let notificationID = sf.system.newGuid().guid;
            
                tracks.forEach((track, index) => {
                    // Notify progress of processing tracks
                    sf.interaction.notify({
                        uid: notificationID,
                        title: "Processing Bypass Data",
                        progress: (index + 1) / tracks.length,
                        message: `Scanning: ${index + 1} of ${tracks.length} tracks`
                    });
            
                    if (track) {
                        // Process insert buttons for "bypassed"
                        track.insertSelectorButtons.forEach((button, i) => {
                            if (button.exists && button.invalidate().value.value.indexOf('bypassed') >= 0) {
                                const slot = i + 1;
                                if (!map.inserts[slot]) {
                                    map.inserts[slot] = [];
                                    elements.inserts.push(slot);
                                }
                                map.inserts[slot].push(track.normalizedTrackName);
                            }
                        });
            
                        // Process send buttons for "muted"
                        track.sendSelectorButtons.forEach((button, i) => {
                            if (button.exists && button.invalidate().value.value.indexOf('muted') >= 0) {
                                const slot = i + 1;
                                if (!map.sends[slot]) {
                                    map.sends[slot] = [];
                                    elements.sends.push(slot);
                                }
                                map.sends[slot].push(track.normalizedTrackName);
                            }
                        });
                    }
                });
            
                return { map, elements };
            }
            
            // Removes items (inserts or sends) from the specified tracks and slots
            function removeItems(names, type, slot) {
                sf.keyboard.press({ keys: "home" });
                sf.ui.proTools.trackSelectByName({ names, deselectOthers: true });
                const original = sf.ui.proTools.selectedTrackNames;
            
                if (original.length > 0) {
                    sf.ui.proTools.trackGetByName({ name: original[0] }).track.trackScrollToView();
                }
            
                sf.ui.proTools.trackSelectByName({ names, deselectOthers: true });
                sf.ui.proTools.selectedTrack.trackInsertOrSendSelect({
                    insertOrSend: type,
                    pluginNumber: parseInt(slot, 10),
                    selectForAllSelectedTracks: true,
                    pluginPath: type === 'Insert' ? ['no insert'] : ['no send']
                });
            
                closeDialog();
                sf.wait({ intervalMs: 250 });
            }
            
            // Batch removes bypassed inserts or muted sends based on the selected option
            function batchRemove(map, elements, option) {
                let processedItems = 0;
                let notificationID = sf.system.newGuid().guid;
                const totalItems = elements.inserts.length + elements.sends.length;
            
                const removeFromSlot = (slot, type, map) => {
                    removeItems(map[slot], type, slot);
                    sf.interaction.notify({
                        uid: notificationID,
                        title: "Removing Bypassed Items",
                        progress: (++processedItems) / totalItems,
                        message: `Removing ${type}s: ${processedItems} of ${totalItems}`
                    });
                };
            
                if (option === "both" || option === "plugins") {
                    elements.inserts.forEach(slot => removeFromSlot(slot, 'Insert', map.inserts));
                }
            
                if (option === "both" || option === "sends") {
                    elements.sends.forEach(slot => removeFromSlot(slot, 'Send', map.sends));
                }
            
                sf.interaction.notify({
                    uid: notificationID,
                    title: "Removing Bypassed Items",
                    progress: 100,
                    message: `Removal complete.`
                });
            }
            
            // Sets the track size for the selected track
            function setTrackSize(size) {
                const selectedTrackH = sf.ui.proTools.selectedTrackHeaders[0];
                try {
                    selectedTrackH.popupMenuSelect({
                        anchor: "MidRight",
                        relativePosition: { x: -10, y: 0 },
                        menuPath: [size],
                        isOption: true,
                        onError: "Continue"
                    });
                } catch (err) {
                    if (selectedTrackH.frame.h <= 79) {
                        sf.ui.proTools.selectedTrack.popupButtons.allItems[2].popupMenuSelect({
                            menuPath: ["Track Height", size],
                            isOption: true
                        });
                    }
                }
            }
            
            // Activates the specified Pro Tools menu options
            function activateProToolsMenus(menuOptions) {
                menuOptions.forEach(menuOption =>
                    sf.ui.proTools.menuClick({
                        menuPath: ["View", "Edit Window Views", menuOption],
                        targetValue: "Enable"
                    })
                );
            }
            
            const proToolsMenuOptions = ["Inserts A-E", "Inserts F-J", "Sends A-E", "Sends F-J"];
            
            function startScript() {
                const userSelection = sf.interaction.selectFromList({
                    items: ["Remove all Bypassed Plugins and Muted Sends", "Remove all Bypassed Plugins", "Remove all Muted Sends"],
                    allowMultipleSelections: false,
                    prompt: "Choose what you want removed",
                    title: "Bypass Cleaner"
                }).list;
            
                if (userSelection.length === 0) return alert("No option selected. Exiting script.");
            
                let chosenOption = userSelection[0];
                sf.ui.proTools.appActivate();
                sf.ui.proTools.mainWindow.invalidate();
            
                const wasLinked = sf.ui.proTools.getMenuItem('Options', 'Link Track and Edit Selection').isMenuChecked;
                if (wasLinked) sf.ui.proTools.menuClick({ menuPath: ["Options", "Link Track and Edit Selection"] });
            
                if (!sf.ui.proTools.mainWindow.title.invalidate().value.startsWith("Edit: ")) {
                    sf.ui.proTools.menuClick({ menuPath: ["Window", "Edit"] });
                }
            
                activateProToolsMenus(proToolsMenuOptions);
                sf.ui.proTools.invalidate();
            
                let tracksForProcessing = sf.ui.proTools.selectedTrackHeaders;
                let firstSelection = sf.ui.proTools.selectedTrackNames;
            
                if (tracksForProcessing.length !== 0) {
                    sf.ui.proTools.trackGetByName({ name: firstSelection[0] }).track.trackScrollToView();
                    sf.ui.proTools.trackSelectByName({ names: firstSelection });
                    setTrackSize('small');
                } else {
                    if (!confirm("No tracks are selected. Would you like to proceed with all visible active tracks?")) {
                        return alert("Operation cancelled.");
                    }
            
                    firstSelection = sf.ui.proTools.visibleTrackNames;
                    sf.ui.proTools.trackGetByName({ name: firstSelection[0] }).track.trackScrollToView();
            
                    const activeTrackNames = sf.app.proTools.tracks.invalidate().allItems.reduce((activeTrackNames, track) => {
                        if (!track.isInactive) activeTrackNames.push(track.name);
                        return activeTrackNames;
                    }, []);
            
                    sf.app.proTools.selectTracksByName({ trackNames: activeTrackNames });
                    setTrackSize('small');
                    tracksForProcessing = sf.ui.proTools.selectedTrackHeaders;
                }
            
                const { map, elements } = findBypassedItems(tracksForProcessing);
            
                if (elements.inserts.length === 0 && elements.sends.length === 0) {
                    return alert("No bypassed plugins or muted sends found.");
                }
            
                let option = chosenOption === "Remove all Bypassed Plugins and Muted Sends" ? "both" :
                             chosenOption === "Remove all Bypassed Plugins" ? (elements.inserts.length === 0 ? (alert("No bypassed plugins found."), undefined) : "plugins") :
                             (elements.sends.length === 0 ? (alert("No muted sends found."), undefined) : "sends");
            
                if (option) batchRemove(map, elements, option);
            
                if (wasLinked) sf.ui.proTools.menuClick({ menuPath: ["Options", "Link Track and Edit Selection"] });
            
                sf.app.proTools.selectTracksByName({trackNames: firstSelection, selectionMode: "Replace"})
                alert("Operation completed.");
            }
            
            // Start the script
            startScript();
            
          • Sreejesh Nair @Sreejesh_Nair
              2025-10-28 18:52:15.933Z

              This will remove inactive sends and inserts from your session. Unless it is specifically bypass you are looking for.

              1. JJonathan Johnson @Jonathan_Johnson
                  2025-10-29 18:56:40.746Z

                  THIS IS GREAT!!!! THANS SO MUCH!!!!