No internet connection
  1. Home
  2. How to

Opening Sessions Automatically.

By Jack Green @Jack_Green
    2023-08-23 11:41:42.987Z2023-08-23 11:58:56.135Z

    Hi,

    I use this chunk of code that i found elsewhere on the forum in several scripts for various repetitive tasks. I think @Kitch may have written it originally but I could be wrong.

    It should open each session selected in finder and perform a function to each of them

    function doToEachSession() {
        sf.ui.finder.appActivate();
        sf.ui.finder.mainWindow.invalidate();
    
        // Filter selected finder paths for Pro Tools Sessions
        const selectedProToolsSessionPaths = sf.ui.finder.selectedPaths.filter(path => path.endsWith(".ptx"));
    
        // Bail out if no Pro Tools sessions are selected
        if (selectedProToolsSessionPaths.length <= 0) {
            alert(`No Pro Tools sessions were selected. Please select Pro Tools session(s) in the the finder and try again`);
            throw 0
        }
    
        // Run for each selected Session path in Finder
        selectedProToolsSessionPaths.forEach(sessionPath => {
            // Open protools session
            sf.file.open({
                path: sessionPath,
                applicationPath: "/Applications/Pro Tools.app",
            });
    
            // Wait for ProTools
            sf.ui.proTools.appWaitForActive();
    
            while (!sf.ui.proTools.invalidate().hasValidUI) {
                sf.wait({ intervalMs: 200 })
            }
    
            sf.wait({
                intervalMs: 2000,
            });
    
            while (sf.ui.proTools.invalidate().windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/)).length.valueOf() == 0) {
                // Ignore Missing I/O
                if (sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.exists) {
                    sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementClick();
                    sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" });
                }
                // Ignore Missing Plug-ins
                if (sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.exists) {
                    sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementClick();
                    sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" });
                }
                // Dismiss missing files..."" dialog if it appears
                dismissMissingFilesDialog({
                    radioButton: "Skip All",
                });
                sf.wait({ intervalMs: 200 })
            }
    
            sf.ui.proTools.waitForNoModals();
    
            importSessionData()
    
        });
    
        sf.ui.finder.appActivateMainWindow();
    
        alert("Import Complete");
    }
    

    It works flawless on smaller sessions however when opening larger session with many plugins it fails before the session is loaded by not dismissing session notes etc. I've tweaked various wait times etc but its still unreliable.

    Any ideas?

    Thanks !

    • 1 replies
    1. Kitch Membery @Kitch2023-08-23 19:48:21.670Z

      Hi @Jack_Green,

      Here is a link to a forum thread that discusses this workflow that may answer your question.

      On a side note, it may be best to use the script help workflow for these kinds of issues, that way the community will get access to error messages and other important information that would be needed to investigate the issue further. See the following article for information on how to use the script help workflow. bit.ly/sfscripthelp

      Rock on!