No internet connection
  1. Home
  2. Support

Auto-Align Post won't close after render

By Linus Gidstedt @Linus_Gidstedt
    2025-09-28 11:34:10.092Z

    Title

    Auto-Align Post won't close after render

    What do you expect to happen when you run the script/macro?

    Hi! I’m having trouble getting Auto-Align Post to close after a render. It seems related to the plug-in doing its analysis while Pro Tools is still rendering the clip.

    If the analysis finishes before the Pro Tools render has completed, SoundFlow tries to close the window too early. When that happens, the window doesn’t close and I hear the system alert beep right when the analysis ends and SoundFlow attempts to close the window.

    Is there a reliable way to make sure the AudioSuite render has fully finished and the window is closed before the script continues?

    Are you seeing an error?

    Could not open popup menu (Auto-Align: Line 297) Popup menu was not found Popup window was not found after waiting 2000 ms

    What happens when you run this script?

    The script is supposed to render a clip with Auto-Align Post and then close the window after the render. Sometimes it works perfectly, but other times it fails to close the window.

    How were you running this script?

    Other

    How important is this issue to you?

    5

    Details

    {
        "inputExpected": "Hi!\nI’m having trouble getting Auto-Align Post to close after a render. It seems related to the plug-in doing its analysis while Pro Tools is still rendering the clip.\n\nIf the analysis finishes before the Pro Tools render has completed, SoundFlow tries to close the window too early. When that happens, the window doesn’t close and I hear the system alert beep right when the analysis ends and SoundFlow attempts to close the window.\n\nIs there a reliable way to make sure the AudioSuite render has fully finished and the window is closed before the script continues?",
        "inputIsError": true,
        "inputError": "Could not open popup menu (Auto-Align: Line 297)\nPopup menu was not found\nPopup window was not found after waiting 2000 ms",
        "inputWhatHappens": "The script is supposed to render a clip with Auto-Align Post and then close the window after the render. Sometimes it works perfectly, but other times it fails to close the window.",
        "inputHowRun": {
            "key": "-MpfwoFyZNOpBC3X5xGI",
            "title": "Other"
        },
        "inputImportance": 5,
        "inputTitle": "Auto-Align Post won't close after render"
    }

    Source

    
    const originalTrackNames = sf.ui.proTools.trackGetSelectedTracks().names;
    
    const originalSelection = sf.ui.proTools.selectionGetInSamples();
    
    //Check if Dia edit 1 and Dia edit 2 exists and if not create them funcion
    /**
     * @param {string} trackName
     */
    function createEditTracks(trackName) {
    
        sf.ui.proTools.appActivateMainWindow();
    
        sf.ui.proTools.menuClick({ menuPath: ["Track", "New..."] });
    
        const win = sf.ui.proTools.windows.whoseTitle.is("New Tracks").first;
    
        win.elementWaitFor();
    
        win.popupButtons.whoseDescription.is("Track type").first.popupMenuSelect({
            menuPath: ["Track Presets", "User"],
        });
    
        win.popupButtons.whoseDescription.is("Track timebase").first.popupMenuSelect({
            menuPath: [trackName],
        });
    
        win.buttons.whoseTitle.is("Create").first.elementClick();
    
        win.elementWaitFor({
            waitType: "Disappear",
        });
    
    }
    
    function dismissDialog(dialogText, buttonName) {
        const dlg = sf.ui.proTools.confirmationDialog;
        //Wait 100ms for dialog box to appear
        dlg.elementWaitFor({
            timeout: 100,
            pollingInterval: 10,
            onError: 'Continue'
        });
    
        if (dlg.children.whoseRole.is("AXStaticText").whoseValue.contains(dialogText).first.exists) {
            dlg.elementWaitFor({
                waitType: "Appear",
            });
    
            dlg.buttons.whoseTitle.is(buttonName).first.elementClick();
    
            dlg.elementWaitFor({
                waitType: 'Disappear',
                timeout: 100,
                pollingInterval: 10,
                onError: 'Continue'
            });
        }
    }
    
    function mainCopy() {
        if (!sf.ui.proTools.isRunning) throw `Please open Pro Tools`;
    
        //Activate Pro Tools createEditTracks window;
        sf.ui.proTools.appActivateMainWindow();
        sf.ui.proTools.mainWindow.invalidate();
    
        //Make sure Link Track and Edit Selection is enabled
        sf.ui.proTools.menuClick({
            menuPath: ["Options", "Link Track and Edit Selection"],
            targetValue: "Enable"
        });
    
        //Show track list
        sf.ui.proTools.menuClick({
            menuPath: ["View", "Other Displays", "Track List"],
            targetValue: "Enable"
        });
    
        //Copy clips
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"] });
    
        // ADDED WAIT HERE after copy/cut
        sf.wait({
            intervalMs: 50,
        });
    
        //Select all destination tracks
        sf.ui.proTools.trackSelectByName({ names: ["Dia edit 1", "Dia edit 2"] });
    
        // Added wait here after scroll to track
        sf.wait({
            intervalMs: 50,
        });
    
        sf.ui.proTools.selectedTrack.trackScrollToView();
    
        ///Re-evaluate here... HACK TO REFRESH MENUS
        sf.keyboard.press({ keys: 'n', fast: true, repetitions: 2 });
    
        //Added Wait here before paste 
    
        sf.wait({
            intervalMs: 50,
        });
    
        //Paste Clips
        sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"] });
    
        dismissDialog("Some automation parameters in the clipboard do not match the paste destination.", "OK");
    }
    
    //Hide all floating windows
    sf.ui.proTools.menuClick({
        menuPath: ["Window", "Hide All Floating Windows"],
    });
    
    //Check if Dia edit 1 and Dia edit 2 exists and if not create them
    if (!sf.ui.proTools.trackNames.some(c => c.substr(0, 10) === "Dia edit 1")) {
        if (sf.ui.proTools.trackNames.some(c => c.substr(0, 10) === "Dia edit 2")) {
            sf.ui.proTools.trackSelectByName({ names: ["Dia edit 2"] });
            if (sf.ui.proTools.selectedTrackNames[0] !== "Dia edit 2")
                throw 'Could not select track: ' + "Dia edit 2";
    
            //Refresh menu
            sf.keyboard.press({ keys: 'n', fast: true, repetitions: 2 });
    
            var trackIsEmpty = sf.ui.proTools.getMenuItem('Track', 'Delete').exists;
    
            if (trackIsEmpty) {
                sf.ui.proTools.getMenuItem('Track', 'Delete').elementClick({}, 'Could not delete track: ' + "Dia edit 2");
                sf.ui.proTools.invalidate();
            }
        }
        sf.ui.proTools.trackSelectByName({ names: originalTrackNames });
        createEditTracks("Dia edit 1");
        createEditTracks("Dia edit 2");
    
    } else if (!sf.ui.proTools.trackNames.some(c => c.substr(0, 10) === "Dia edit 2")) {
        sf.ui.proTools.trackSelectByName({ names: ["Dia edit 1"] });
        createEditTracks("Dia edit 2");
    };
    
    sf.ui.proTools.mainWindow.invalidate();
    
    //Select originally selected tracks
    sf.ui.proTools.trackSelectByName({ names: originalTrackNames });
    
    mainCopy();
    
    //Clear Clip Gain
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Clear Special", "Clip Gain"],
    });
    
    /* //Clear Clip Effects
     sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Clear Special", "Clip Effects"],
    });  */
    
    //Clear Fades
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Fades", "Delete"],
    });
    
    sf.ui.proTools.trackSelectByName({
        names: ["Dia edit 1", "Dia edit 2"],
    });
    
        ///Re-evaluate here... HACK TO REFRESH MENUS
        sf.keyboard.press({ keys: 'n', fast: true, repetitions: 2 });
    
    //Trim Clips to File Boundaries
    sf.wait({ intervalMs: 50 });
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Trim Clip", "To File Boundaries"],
    });
    
    sf.ui.proTools.trackSelectByName({
        names: ["Dia edit 2"],
    });
    
    
    function autoalign() {
        // get window
        let asWin = sf.ui.proTools.getAudioSuiteWindow("Auto-Align Post");
    
        //Open the plugin
        asWin = sf.ui.proTools.audioSuiteOpenPlugin({
            category: 'Other',
            name: "Auto-Align Post"
        }).window;
    
        //Set processing options
        asWin.audioSuiteSetOptions({
            processingInputMode: "ClipByClip",
            processingOutputMode: "CreateIndividualFiles"
        });
    
        // Set to whole file
        asWin.getFirstWithTitle("Whole file").elementClick();
    
        //Select Key Input
        sf.ui.proTools.firstAudioSuiteWindow.popupButtons.whoseTitle.is('Key Input').first.popupMenuSelect({
            menuPath: ["Dia edit 1"],
        });
    
        //Render
        asWin.audioSuiteRender();
    
        //Close Window
        asWin.windowClose();
    }
    
    autoalign();
    
    //Extend Edit Up
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Selection", "Extend Edit Up"],
    });
    
    //Clear clips
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Clear"],
    });
    
    //Set Original Selection
    sf.ui.proTools.selectionSetInSamples({
        mainCounter: originalSelection.selectionStart,
        selectionStart: originalSelection.selectionStart,
        selectionEnd: originalSelection.selectionEnd,
        selectionLength: originalSelection.selectionLength,
    });
    
    sf.ui.proTools.trackSelectByName({
        names: originalTrackNames,
        deselectOthers: true
    });
    
    sf.wait({ intervalMs: 50 });
    
    //Remove Edit from Top
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Selection", "Remove Edit from Top"],
    });
    
    //Copy Clip Gain
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Copy Special", "Clip Gain"],
    });
    
    //Clear Find in Clip List
    sf.keyboard.press({ keys: "shift+command+d" });
    
    // Setup a function that opens the Clip Rename window, gets the Channel Name value and saves it to a variable.
    sf.ui.proTools.menuClick({
        menuPath: ["Clip", "Rename..."]
    });
    
    sf.wait({ intervalMs: 100 })
    if (!sf.ui.proTools.windows.whoseTitle.is("Name").first.exists) {
        sf.keyboard.press({ keys: "option+command+k" });
        sf.ui.proTools.menuClick({
            menuPath: ["Clip", "Rename..."]
        });
    }
    
    //Copy Channel Name
    if (!sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.whoseTitle.is('Clip Info').first.children.whoseRole.is("AXStaticText").whoseValue.is('User Time Stamp:').first.exists) {
        sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.whoseTitle.is('Clip Info').first.mouseClickElement({
            relativePosition: { "x": 12, "y": 12 },
        });
    };
    
    let channelName = sf.ui.proTools.windows.whoseTitle.is("Name").first.groups.whoseTitle.is("Clip Info").first.children.whoseRole.is("AXStaticText").allItems[8].value.invalidate().value;
    
    /* if (channelName == "Take: ") {
        sf.interaction.displayDialog({
            title: "Could not find Channel Name",
            prompt: "Show clip into and hit OK on this dialog",
            buttons: ["Cancel", "OK"],
            cancelButton: "Cancel",
            onCancel: "Abort"
        });
    
        channelName = sf.ui.proTools.windows.whoseTitle.is("Name").first.groups.whoseTitle.is("Clip Info").first.children.whoseRole.is("AXStaticText").allItems[8].value.invalidate().value;
    } */
    
    sf.ui.proTools.windows.whoseTitle.is("Name").first.buttons.whoseTitle.is("Cancel").first.elementClick();
    
    sf.ui.proTools.appActivateMainWindow();
    sf.ui.proTools.invalidate().selectedTrack.titleButton.popupMenuSelect({
        isRightClick: true,
        targetValue: "Enable",
        menuPath: ["Field Recorder Guide Track"]
    });
    
    sf.ui.proTools.clipSelectFieldRecorderChannelOneClip({
        channelNameContains: [channelName],
        isOkayIfNoMatch: true,
        onError: "Continue",
        bottomUpSearch: true
    });
    
    //Paste Clip Gain
    sf.ui.proTools.menuClick({
        menuPath: ["Edit", "Paste"],
    });
    
    //Unhide all floating windows
    sf.ui.proTools.menuClick({
        menuPath: ["Window", "Hide All Floating Windows"],
    });
    
    /* sf.interaction.displayDialog({
        hiddenAnswer: true,
        title: "Confirmation",
        prompt: "Auto-Align done!",
        giveUpAfterSeconds: 1,
    }); */
    
    log("Auto-Align done!")
    

    Links

    User UID: mag5iiYxaiZ5xli5fz9O3mUjFyp1

    Feedback Key: sffeedback:mag5iiYxaiZ5xli5fz9O3mUjFyp1:-OaF5VhSAZ-DjrS_LMLu

    Feedback ZIP: 5es3BJJRml9u/rdo3vXveRWDYumkFSAKqypjBOUh5Dm8W+bL62f9TSc5vgpc+oevGY+sJ7v0jo2AXgL+GS2pS13coM1mPRZpt35zxlXTZ+m9F3nPVQFF5t16d/6RVYCIGYjaAA85qnjR+VCACrdLtdKODWmSXXpCezHIgEI9ZqgIgW68R3vJfvTk7QX0xSRlv+lj6EW5mSSOzVZey2JIuRjqxNqYxJTrPaKMESbO4LeGg/1iJYg4WshABJcNqik5aSRpx18QwGuSqNOZ2GLZ/DAzTVWed4oB+QiKLEKIXOXRMCG8bvt/jPHBCeLupMMrYc3gNaqvZVomzkyKMQ48sHVNgdue+1QkCdGXnZEbKWQ=

    • 0 replies