No internet connection
  1. Home
  2. How to

Help Me Improve my script - creating a new session

By Randall Smith @Randall_Smith
    2021-11-01 14:12:25.223Z
    var promURL = 'http://denpwmf42:8130/IBMS/api/projects/PROM.'
    
    function getIBMSData(promNumber) {
        var fullURL = promURL + promNumber + '/info'
        return sf.net.httpRequest({
            url: fullURL,
        }).asJson();
    };
    
    var promNumber = prompt("Enter your PROM number: ");
    
    var response = getIBMSData(promNumber);
    var jsonObj = response.Body;
    
    if (jsonObj.length > 0) {
        //Get the name of the project from the first version of the json object
        log(jsonObj[0].Name);
        //Do something with jsonObj, like iterate over contents and log Version IDs
        for (var x = 0; x < jsonObj.length; ++x) {
            var thisVersion = jsonObj[x];
            log(thisVersion.VersionBroadcasterReferenceId);
        }
    }
    
    var schedulAllNum = prompt("Enter the Project Number:");
    
    function DayMonthYear() {
        var now = new Date();
        return ('0' + (now.getMonth() + 1)).toString().slice(-2) +
            ('0' + (now.getDate()).toString()).slice(-2) +
            ('0' + now.getFullYear().toString()).slice(-2);
    
    }
    
    const todaysDate = DayMonthYear()
    const editorInit = "RCS"
    const outputDir = "/Volumes/Audio2 Work SSD/"
    var tempSessionName = (jsonObj[0].Name);
    
    
    
    sf.ui.proTools.appActivate();
    
    function createNewProToolsSession(projectNumber, sessionName, outputDirectory, editorInitials, dateToday) {
    
        sf.ui.proTools.menuClick({
            menuPath: ["File", "Create New..."],
        });
        sf.ui.proTools.appActivate();
    
        sf.wait({
            intervalMs: 2000,
        });
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.windowMove({
            position: { "x": 10, "y": 10 },
        });
    
    
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.elementWaitFor();
    
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.checkBoxes.whoseTitle.is("Create From Template").first.checkboxSet({
            targetValue: "Enable",
        });
    
        //opens correct template directory
        //sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.whoseDescription.is("").first.popupMenuSelect({
        //    menuPath: ["STARZ"],
        //});
    
        //opens clean IO profile 
        //sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.whoseDescription.is("").allItems[4].popupMenuSelect({
        //    menuPath: ["Audio 2 Clean Io 031720"],
        //});
    
        //sets template parameters in case of change
        //sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.whoseDescription.is("").allItems[2].popupMenuSelect({
        //    menuPath: ["48 kHz"],
        //});
    
        //sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.whoseDescription.is("").allItems[3].popupMenuSelect({
        //    menuPath: ["24-bit"],
        //});
    
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.radioButtons.whoseTitle.is("Default location").first.checkboxSet({
            targetValue: "Enable",
        });
    
    
    
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.buttons.whoseTitle.is("Location...").first.elementClick();
    
        //sets the output directory
        sf.wait({
            intervalMs: 300,
        });
    
    
        sf.keyboard.press({
            keys: "slash",
        });
        sf.wait({
            intervalMs: 300,
        });
    
        sf.keyboard.press({
            keys: "backspace",
        });
        sf.wait({
            intervalMs: 300,
        });
    
        sf.keyboard.type({
            text: outputDirectory,
        });
        sf.wait({
            intervalMs: 300,
        });
    
        sf.keyboard.press({
            keys: "enter",
        });
    
        sf.ui.proTools.windows.whoseTitle.is("Open").first.getElement("AXDefaultButton").elementClick();
    
        var currentVersion = prompt("What is the current version?'");
    
        var newSessionName = (projectNumber + " " + sessionName + ' v' + currentVersion + ' ' + editorInitials + ' ' + dateToday);
    
        alert(newSessionName);
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.textFields.first.elementClick();
    
        //sets the name
        //sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.textFields.first.elementSetTextAreaValue({
        //    value: newSessionName,
        // });
        sf.keyboard.type({
            text: newSessionName,
        });
        sf.wait({
            intervalMs: 300,
        });
        sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.buttons.whoseTitle.is("Create").first.elementClick();
    
    }
    
    
    function createSubFoldersInProjectFolder(folderNames) {
        var sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/');
    
        const createSubFolder = name => {
            sf.file.directoryCreate({ path: sessionFolder + '/' + name, onError: 'Continue' });
        };
    
        folderNames.map(createSubFolder);
    }
    
    createNewProToolsSession(schedulAllNum, tempSessionName, outputDir, editorInit, todaysDate);
    
    sf.wait({
        intervalMs: 20000,
    });
    
    sf.ui.proTools.waitForNoModals({
        onCancel: "Abort",
        onError: "Continue",
    });
    
    
    createSubFoldersInProjectFolder([
        '01 AAF EDL',
        '02 File Based Deliveries',
        '02 File Based Deliveries/01 Sub and Gen',
        '02 File Based Deliveries/02 Air Masters',
        '02 File Based Deliveries/03 Stem Sets',
        '02 File Based Deliveries/04 Approval Files',
        '02 File Based Deliveries/05 Cue Sheets',
        '03 Old Sessions',
        '04 Video Files',
        '05 WAVs MP3s',
    ]);
    

    So, I have this script to create a new PT project with a name pulled via API from an internal source. That part is working.

    The part that is commented out, where Pro Tools will define the parameters for the new session, from pulling the correct template down fails out randomly. The section where it creates the Session folder structure fails out about %25 of the time as well.

    What can I do to improve this?

    Randall

    • 8 replies
    1. The part where you set the location in the dialog box, you're using keyboard simulation unnecessarily. Instead use something like the navigateToInDialog code here:

      1. You've set the waitForNoModals to continue on any errors. This means your createSubFoldersInProjectFolder could run before PT is done creating the session. This could also lead to instability.

        1. Couple of other things. Ideally, your script should start with the prompt, so that any input from the user is collected immediately when the script is run, and then the rest can run unsupervised. This will give you the largest workflow improvement.

          The sub folders you're creating in the project folder don't need to wait for the project to be created first, I would imagine?

          1. In terms of template selection not always working, if those UI fields are disabled until you select Create from template, then there's a chance SF sometimes is so fast at trying to interact with those disabled fields that PT hasn't yet enabled them when you try to manipulate them.

            You could fix that with some retry logic around the first thing you try to manipulate after you've enabled the Create from template.

            1. Really cool workflow btw, great to see this kind of integration being done.

              Lmk if you need access to our paid script support services, if you're interested feel free to reach out at support@soundflow.org

              1. In reply tochrscheuer:
                RRandall Smith @Randall_Smith
                  2022-03-10 17:21:51.933Z

                  Thank you for your help/suggestions. Is there a way to have soundflow choose a specific template (by name)?

                  Randall

                  1. Hi Randall,

                    Apologies for the late reply, I'm currently very busy with the next version of SF.
                    Yes, I believe that should be possible. One way to do it that should definitely work is if you locate the template file by opening the "open" dialog to locate it on your drive - I know plenty of scripts in the forum that can navigate those dialogs.
                    Unfortunately, I won't have time to write such a script right now though :/ Hopefully you'll be able to find some bits and pieces, try to search for navigateToInDialog - for example here:

                    1. RRandall Smith @Randall_Smith
                        2022-03-22 20:22:21.198Z

                        I ended up creating an IF/ELSE loop with 'Open File:' pointed to the template. Seems to work well enough, but will have to be rebuilt every time there is an update.

                        Thanks.

                        Randall