No internet connection
  1. Home
  2. How to

Script Import Window Configirations

By Le Bras Romain @Le_Bras_Romain
    2019-12-04 21:18:41.982Z2019-12-04 21:34:44.077Z

    Hello,
    Here is a script I've just made to import via a short cut your window configurations. I'm pretty new to sf, so don't hesitate if you have any advices :)

    // Open up Import Session Data
    sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
    // Direction of the Session
    sf.keyboard.press({
        keys: "cmd+shift+g",
    });
    sf.keyboard.type({
        text: "/Volumes/romain 3To/OPJ 2019/Templates/Windows Configuration.ptx",
    });
    sf.wait({
        intervalMs: 500,
    });
    sf.keyboard.press({
        keys: "return",
    });
    sf.wait({
        intervalMs: 500,
    });
    sf.keyboard.press({
        keys: "return",
    });
    // Check the parameter Windows Configurations
    
    var prefsWin = sf.ui.proTools.dialogWaitForManual({ dialogTitle: 'Import Session Data' }).dialog;
    
    var SessionDataGroup = prefsWin.getFirstWithTitle("Session Data");
    var WindowConfigurations = SessionDataGroup.getFirstWithTitle("Window Configurations");
    WindowConfigurations.checkboxSet({
        targetValue: 'Enable' //or 'Enable' or 'Disable'
    });
    prefsWin.getFirstWithTitle("OK").elementClick();
    
    Solved in post #4, click to view
    • 21 replies

    There are 21 replies. Estimated reading time: 16 minutes

    1. Hi Romain :)

      Almost there - you need the three backticks without the parentheses ;)

      1. LLe Bras Romain @Le_Bras_Romain
          2019-12-04 21:38:37.388Z

          hahaha yes I've jusst figured it out editing the last script haha thanks you very much

          1. In reply tochrscheuer:

            I would do it like this:

            function navigateToInDialog(win, path) {
                //Open the Go to... sheet
                sf.keyboard.type({ text: '/' });
            
                //Wait for the sheet to appear
                var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
            
                //Set the value of the combo box
                sheet.comboBoxes.first.value.value = path;
            
                //Press OK
                sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"');
            
                //Wait for sheet to close
                win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time');
            }
            
            function importSession(sessionPath) {
                // Open up Import Session Data
                sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
            
                // Wait for window to open
                var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first;
            
                // Navigate to folder
                navigateToInDialog(importWin, sessionPath);
            
                // Click Open
                importWin.buttons.whoseTitle.is('Open').first.elementClick();
            
                // Wait for import window to close
                importWin.elementWaitFor({ waitForNoElement: true });
            }
            
            function main() {
                //Import session
                importSession("/Volumes/romain 3To/OPJ 2019/Templates/Windows Configuration.ptx");
            
                //Wait for Import Session Data
                var importSessionWin = sf.ui.proTools.windows.whoseTitle.is('Import Session Data').first.elementWaitFor().element;
            
                //Enable "Window Configurations"
                var sessionDataGroup = importSessionWin.getFirstWithTitle("Session Data");
                var windowConfigurations = sessionDataGroup.getFirstWithTitle("Window Configurations");
                windowConfigurations.checkboxSet({
                    targetValue: 'Enable' //or 'Enable' or 'Disable'
                });
            
                //Click OK
                importSessionWin.getFirstWithTitle("OK").elementClick();
            }
            
            main();
            
            ReplySolution
            1. VVanessa Garde @Vanessa_Garde
                2023-01-20 15:44:26.028Z

                Trying this scripts but it's giving me an error on line 9:

                any hints to get it resolved?

                Thanks!

                My line 9 is:

                var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;

                Vanessa G.

                1. Hey Vanessa, this is all apple’s fault. :p

                  Every time they update the OS they change how the sheets look and work and Christian is stuck reworking the navigate to code. The latest version is in the protools main package but obviously that doesn’t roll back into the forum posts.

                  I've taken the liberty of using that most updated code in import scripts that you can download from the store in my ‘Automated Protools Imports’ package. Use the ‘Auto Import Template' for the more up to date version of this script. Or find it here Creating an "Import Mix Template" macro. #post-2 as just a script.

                  I've attached a quick video here on how to set up your own preset for 'Auto Import Template' in the package. I hope this helps!
                  https://www.dropbox.com/s/4fprhkek3lj2e0q/AUTO IMPORT PRESET.mov?dl=0

                  Bests,
                  Owen

                  1. Oh and I just read the actual subject header lol. This is only for window configs... lol. Please ignore my post. I'll update the package to include that option at a later date, but here's the OG script with the new navigate to code see if it works for you.

                    // Navigate to File Function
                    function navigateTo(path) {
                        //Get a reference to the focused window in the frontmost app:
                        var win = sf.ui.frontmostApp.focusedWindow;
                    
                        //Open the Go to... sheet
                        sf.keyboard.type({ text: '/' });
                    
                        //Wait for the sheet to appear
                        var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
                    
                        //It's a combo box on older OS'es, from 12.something it's a text field
                        if (sheet.comboBoxes.first.exists) {
                            sheet.comboBoxes.first.value.value = path;
                    
                            //Press OK
                            sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"');
                        }
                        else {
                            //Newer OS.
                            //TextField with AXConfirm
                            var textField = sheet.textFields.first;
                            if (!textField.exists) throw `Can't find text field`;
                            textField.value.value = path;
                    
                            sheet.elementRaise();
                    
                            textField.mouseClickElement({
                                relativePosition: { x: 5, y: 5 },
                            });
                    
                            sf.keyboard.press({ keys: 'return' });
                        }
                    
                        //Wait for sheet to close
                        win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 2500 }, '"Go to" sheet didn\'t close in time');
                    }
                    
                    /// Import Selected Function
                    function importSession(selectedPath) {
                        const numberOfTriesClickingOpen = 40;
                        const timeToWaitBetweenOpenAttempts = 200;
                    
                        sf.ui.proTools.appActivateMainWindow();
                    
                        // Open up Import Session Data
                        sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
                    
                        // Wait for window to open
                        var importWin = sf.ui.proTools.windows.whoseTitle.is('Open').first;
                    
                        // Navigate to folder
                        navigateTo(selectedPath);
                    
                        sf.wait({
                            intervalMs: 50,
                        });
                    
                        // Click Open
                        //Press Open, try up to 10 times
                        var openSuccess = false;
                        for (var i = 0; i < numberOfTriesClickingOpen; i++) {
                            try {
                                if (importWin.invalidate().buttons.whoseTitle.is('Open').first.elementClick({ onError: 'Continue' }).success) {
                                    openSuccess = true;
                                    break;
                                }
                            } catch (err) { }
                    
                            sf.wait({ intervalMs: timeToWaitBetweenOpenAttempts });
                        }
                        if (!openSuccess)
                            throw "Could not click 'Open'";
                    
                    
                        // Wait for import window to close
                        importWin.elementWaitFor({ waitForNoElement: true });
                    }
                    
                    function main() {
                        //Import session
                        importSession("/Volumes/romain 3To/OPJ 2019/Templates/Windows Configuration.ptx");
                    
                        //Wait for Import Session Data
                        var importSessionWin = sf.ui.proTools.windows.whoseTitle.is('Import Session Data').first.elementWaitFor().element;
                    
                        //Enable "Window Configurations"
                        var sessionDataGroup = importSessionWin.getFirstWithTitle("Session Data");
                        var windowConfigurations = sessionDataGroup.getFirstWithTitle("Window Configurations");
                        windowConfigurations.checkboxSet({
                            targetValue: 'Enable' //or 'Enable' or 'Disable'
                        });
                    
                        //Click OK
                        importSessionWin.getFirstWithTitle("OK").elementClick();
                    }
                    
                    main();
                    

                    Untested see if that helps!

                    1. VVanessa Garde @Vanessa_Garde
                        2023-01-21 15:13:57.412Z

                        Thanks Owen for your message.

                        Unfortunately, it's giving the same error as before. PT 2012.12 and Big Sur, here.

                        Thanks for the advice.

                        1. I'm sorry to hear that, I've updated my package in the store so users can toggle the check boxes in Session Data:

                          Give that a shot and let me know if it works.

                          Bests,
                          Owen

                          1. RRobert Acocella @Robert_Acocella
                              2025-04-09 18:56:57.250Z

                              After trying both a scripted version above, and this Auto Import Template, I realize both are requiring an extra key input from me (Return), and I don't mind. But this macro kicks this error. Even despite the error, it does open the Session Data import window, and the correct boxes are all checked, only requiring me to click OK or press Return on my keyboard. Not complaining, just curious why it's doing that. I'm new to this and trying to dive into as much as I can for educational purposes.

                              1. Yo boss, I have not updated this to the latest protools import window. It's been happening to me too lol, just been too busy working to fix it vs hitting the return button too lol.

                                1. RRobert Acocella @Robert_Acocella
                                    2025-04-09 19:00:57.249Z

                                    lol, totally not a complaint, so I hope you didn't take it as one. After reading this thread I noticed that this is one of those things that's subject to constant change because of OS and PT versions and I guess I was just looking for confirmation that it was that, and not something I was doing wrong. Hitting return isn't the worst thing I have to do every day!

                                    1. Didn't take it that way at all! All good! This package has been on my 'update to do' list. It's in need of a general overahaul.

                                      1. In reply toRobert_Acocella:

                                        Yo I fixed this today, you can on your side pretty easy too, make an editable copy and go to line 110 it should read
                                        const sessionDataCheckboxes = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first.groups.whoseTitle.is("Session Data").first

                                        change it to
                                        let sessionDataCheckboxes = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first.groups.whoseTitle.is("Main Playlist Options").first;

                                        1. RRobert Acocella @Robert_Acocella
                                            2025-04-12 21:33:01.105Z

                                            I don't have a line 110, mine only goes to 98. Oh boy...

                                            1. Bhahah, I must be looking at the wrong package. I fixed the #0 thing in a different script lol.

                                              1. Out of curiousity @Kitch does this SDK work?

                                                sf.app.proTools.importSessionData({
                                                    adjustSessionStartTimeToMatchSource : false,
                                                    audioMediaOptions : "LinkToSourceAudio",
                                                    executionMode : "Foreground",
                                                    importClipGain : true,
                                                    importClipsAndMedia : false,
                                                    importVolumeAutomation : true,
                                                    sessionPath : "/Volumes/OCD 2/SUPERVISOR_TEMPLATE.ptx",
                                                    audioHandleSize : 0
                                                })
                                                

                                                So far if I don't include audioHandleSize it logs : audio_handle_size (PT_UnknownError) (SDK Auto Import: Line 1)
                                                And if I do include audioHandleSize it logs Unable to complete the command due to an unknown error. (PT_InvalidParameter) (SDK Auto Import: Line 1)

                                                Basically Robert was seeing if we could shortcut this whole script and use the latest SDK to get this done, but I'm having trouble getting it to run.

                                                1. Holy Shit! That worked! Just filled out a lot more parameters.

                                                  @Robert_Acocella try this instead! You can change the things you need to, the most important one to change is

                                                  sessionPath : your pathname here

                                                  sf.app.proTools.importSessionData({
                                                      adjustSessionStartTimeToMatchSource : false,
                                                      audioMediaOptions : "LinkToSourceAudio",
                                                      executionMode : "Background",
                                                      importClipGain : true,
                                                      importClipsAndMedia : false,
                                                      importVolumeAutomation : true,
                                                      sessionPath : "/Volumes/OCD 2/SUPERVISOR_TEMPLATE.ptx",
                                                      audioHandleSize : 0,
                                                      onError : "ThrowError",
                                                      playlistOptions :"DoNotImport",
                                                      timecodeMappingStartTime : `01:00:00:00`,
                                                      timecodeMappingUnits :"MaintainAbsoluteTimeCodeValues",
                                                      trackMatchOptions : "ImportAsNewTrack",
                                                      videoMediaOptions : "LinkToSourceVideo"
                                                  
                                                  })
                                                  

                                                  Excuse me while i rebuild all my session Import scripts :P

                                                  1. RRobert Acocella @Robert_Acocella
                                                      2025-04-12 22:53:03.066Z

                                                      I'm not sure this is what I need. I need it to import a Window Config from a session, nothing else. I don't see a line for Window Config and I have no idea how to script to even put it there.

                        2. L
                          In reply toLe_Bras_Romain:
                          Le Bras Romain @Le_Bras_Romain
                            2019-12-05 00:23:16.720Z

                            Thank you Christian,
                            First time for me that I have to deal with functions in SF. I will inform me.
                            I don't know what i'm doing wrong with your script but i'm stuck with this message and can 't go ahead :

                            1. LLe Bras Romain @Le_Bras_Romain
                                2019-12-05 01:01:36.851Z

                                I ' ve found the solution. I have to replace all “Go“ and “Openr“ in the script by the french words “Aller“ et “Ouvrir“
                                Thanks a million for the script.

                                1. Great you found out how to adapt it :)