No internet connection
  1. Home
  2. How to

script to open protools with a pre-defined engine

By Les Cooper @Les_Cooper
    2022-12-05 19:09:03.472Z

    I run Protools on a laptop that goes between being connected to a hub and an audio interface in my studio and running remote in various locations. I'd love to have a script that will open protools with a pre-defined engine for when I plug into my hub. Often, it will open with whatever the last used audio engine was so I have to change the engine and restart the session.
    Ideally, the script would launch Protools with the same behavior as launching with the 'n' key held down to launch the choose engine dialog and then select my audio interface which I would define in a variable as part of the script.

    • 6 replies
    1. Mitch Willard @Mitch_Willard
        2022-12-06 00:31:35.461Z2022-12-06 04:35:24.794Z

        Hi @Les_Cooper,

        You can just adjust the playback engine after launching Pro Tools, instead of writing a function to hold down 'n' on launch.

        try this:

        function adjustPlaybackEngine() {
            if (!sf.ui.proTools.isRunning) {
        
                function waitForPtLaunch() {
        
                    while (!sf.ui.proTools.invalidate().hasValidUI) {
                        sf.wait({ intervalMs: 200 })
                    }
                    for (var i = 0; i < 10; i++) {
                        sf.ui.proTools.waitForNoModals();
                    }
                }
        
                var playbackEngineArray = ['Universal Audio Thunderbolt', 'MacBook Pro Speakers'] ////Add any additional PLAYBACK ENGINE settings to here.
                var selectedPaybackEngine = sf.interaction.popupSearch({
                    title: "Select Playback Engine",
                    items: playbackEngineArray.map(p => ({
                        name: p,
                    })),
                    columns: [
                        { name: 'Please Select Playback Engine', key: 'name', width: 80 },
                    ]
                }).item.name;
        
                sf.app.launch({
                    path: "/Applications/Pro Tools.app",
                });
        
                sf.interaction.displayDialog({
                    prompt: 'Please wait for Pro Tools to Load,\n\nThe Playback Engine "' + selectedPaybackEngine + '" will be selected after launching Pro Tools\n\nThis dialog will disappear after a few seconds.',
                    title: 'PRO TOOLS IS LOADING',
                    giveUpAfterSeconds: 10,
                }).button
        
                waitForPtLaunch();
        
                sf.ui.proTools.menuClick({
                    menuPath: ['Setup', 'Playback Engine...']
                });
        
                let playbackEngineDlg = sf.ui.proTools.windows.whoseTitle.is("Playback Engine").first;
        
                playbackEngineDlg.elementWaitFor({
                    waitType: 'Appear',
                    timeout: 1000,
                    pollingInterval: 50
                });
        
                if (playbackEngineDlg.popupButtons.first.value.value != selectedPaybackEngine)
                    playbackEngineDlg.popupButtons.first.popupMenuSelect({
                        menuPath: [selectedPaybackEngine],
                    });
        
                playbackEngineDlg.buttons.whoseTitle.is("OK").first.elementClick();
        
                playbackEngineDlg.elementWaitFor({
                    waitType: 'Disappear',
                    timeout: 1000,
                    pollingInterval: 50
                });
        
                alert('Your Playback Engine has been set to:\n\n' + selectedPaybackEngine + '.')
        
            };
        };
        
        adjustPlaybackEngine();
        
        

        Cheers

        Mitch

        1. LLes Cooper @Les_Cooper
            2022-12-06 15:26:38.555Z

            Hey @Mitch_Willard

            First off, thank you so much for this. Too cool!

            I'm wondering if it would be possible to amend this a bit for some other situations.
            I'd like to be able to have a version where it chooses 'Universal Audio Thunderbolt' automatically - without any additional dialogs. This way, I could make a few different versions with different engines to put on a deck.
            Thanks again Mitch!
            Les

            1. Mitch Willard @Mitch_Willard
                2022-12-06 21:21:26.479Z

                Super easy @Les_Cooper

                Will get it to you shortly, will be in front of a computer soon.

                Mitch

                1. Mitch Willard @Mitch_Willard
                    2022-12-06 21:43:10.777Z

                    Here you go @Les_Cooper,

                    Just replace 'Universal Audio Thunderbolt' with whichever Playback Engine setting you'd like to use.

                    function adjustPlaybackEngine(selectedPlaybackEngine) {
                        if (!sf.ui.proTools.isRunning) {
                    
                            function waitForPtLaunch() {
                    
                                while (!sf.ui.proTools.invalidate().hasValidUI) {
                                    sf.wait({ intervalMs: 200 })
                                }
                                for (var i = 0; i < 10; i++) {
                                    sf.ui.proTools.waitForNoModals();
                                }
                            }
                    
                            sf.app.launch({
                                path: "/Applications/Pro Tools.app",
                            });
                    
                            sf.interaction.displayDialog({
                                prompt: `Please wait for Pro Tools to Load,\n\nThe Playback Engine "${selectedPlaybackEngine}" will be selected after launching Pro Tools\n\nThis dialog will disappear after a few seconds.`,
                                title: 'PRO TOOLS IS LOADING',
                                giveUpAfterSeconds: 10,
                            }).button
                    
                            waitForPtLaunch();
                    
                            sf.ui.proTools.menuClick({
                                menuPath: ['Setup', 'Playback Engine...']
                            });
                    
                            let playbackEngineDlg = sf.ui.proTools.windows.whoseTitle.is("Playback Engine").first;
                    
                            playbackEngineDlg.elementWaitFor({
                                waitType: 'Appear',
                                timeout: 1000,
                                pollingInterval: 50
                            });
                    
                            if (playbackEngineDlg.popupButtons.first.value.value != selectedPlaybackEngine)
                                playbackEngineDlg.popupButtons.first.popupMenuSelect({
                                    menuPath: [selectedPlaybackEngine],
                                });
                    
                            playbackEngineDlg.buttons.whoseTitle.is("OK").first.elementClick();
                    
                            playbackEngineDlg.elementWaitFor({
                                waitType: 'Disappear',
                                timeout: 1000,
                                pollingInterval: 50
                            });
                    
                            alert(`Your Playback Engine has been set to:\n\n'${selectedPlaybackEngine}'.`)
                    
                    
                        };
                    };
                    
                    adjustPlaybackEngine('Universal Audio Thunderbolt'); ////Replace 'Universal Audio Thuderbolt' with desired PLAYBACK ENGINE setting here.
                    
                    

                    Thanks

                    Mitch

                    1. LLes Cooper @Les_Cooper
                        2022-12-06 21:54:39.575Z

                        Too cool!
                        Thanks again Mitch.

                2. J
                  In reply toLes_Cooper:
                  Jonathan Dakers @Jonathan_Dakers
                    2024-12-04 07:48:31.697Z

                    Hi! This script isn't working for me, running Pro Tools 2024.10 in MacOS sequoia. Pro Tools opens, a box pops up saying it will select the right engine, but once Pro Tools is open nothing happens. Any ideas?

                    edit: Okay now when I opened a project the prompt came up saying the playback engine had been set. Maybe the script is waiting for something that only gets triggered when a project is open?