No internet connection
  1. Home
  2. Script Sharing

Open all Plugin inserts on selected track

By Sreejesh Nair @Sreejesh_Nair
    2024-11-10 08:45:38.102Z

    This script will open all the active plugins on a selected track. The thing is it opens it from last to first so that when the plugin windows are layered, the are in order with the first insert on the topmost and the last one bottom.

    let track = sf.ui.proTools.selectedTrack;
    
    function getInsertWin(track, insertIndex) {
        const insertChars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
        const insertChar = insertChars[insertIndex];
        const trackName = track.normalizedTrackName;
        return sf.ui.proTools.windows.whoseTitle.contains('Plug').filter(w => {
            if (w.popupButtons.whoseTitle.is('Track Selector').first.value.value !== trackName) return false;
            if (w.popupButtons.whoseTitle.is('Insert Position selector').first.value.value !== insertChar) return false;
            return true;
        })[0];
    }
    
    // Iterate through the track's insertSelectorButtons in reverse order
    for (let i = track.insertSelectorButtons.length - 1; i >= 0; i--) {
        let button = track.insertSelectorButtons[i];
    
        // Skip if the button doesn't exist or if it's inactive
        if (!button.exists || button.invalidate().value.value.startsWith("inactive")) continue;
    
        // Check if the insert button is unassigned
        if (track.insertButtons[i].value.value === "unassigned") continue;
    
        // Try to get the plugin window for this insert
        let pluginWin = getInsertWin(track, i);
    
        // If the plugin window is not open, open it
        if (!pluginWin) {
            track.insertButtons[i].elementClick();
    
            // Wait until the window opens or skip after some attempts
            let attempts = 0;
            while (attempts < 10) {
                pluginWin = getInsertWin(track, i);
                if (pluginWin) break;
                sf.wait({ intervalMs: 100 });
                attempts++;
            }
    
            // If the plugin window opened, disable target mode
            if (pluginWin) {
                pluginWin.buttons.whoseTitle.is('Target button').first.elementClick();
            }
        }
    }
    
    • 0 replies