No internet connection
  1. Home
  2. How to

Batch Rename Tracks with new session name

By Goetz Botzenhardt @Goetz_Botzenhardt
    2022-10-20 14:36:34.318Z

    Hello,

    I mix music for film and TV.

    I love what you guys are doing with Soundflow and I really want to adopt this into my workflow. I can't wait to save lots of time by automating the mundane and repetitive.

    Atm, I'm trying automate a process which I have to do many times a day.

    After I have finished mixing a cue (ie 6m36), I will the start on the next cue (ie6m37).

    Once I have saved my session under the name of the new cue (6m37)
    I have to rename all my prints tracks.

    In this example, this means replacing '6m36' in the track name with '6m37',

    so that track name:

    ISS 6m36_Final_5.1_Stem 1 Orchestra 1

    will change to:

    ISS 6m37_Final_5.1_Stem 1 Orchestra 1

    When I do this manually in the 'Batch Track Rename' window, I delete what was in 'find' (ie '6m35') and I replace it with what was in 'Replace' (6m36).

    I then paste the new session name (6m37) into Replace.

    In this example 'Batch Track Rename' looks like this when I open it:

    After my alterations it should look like this:

    I managed to write the code to find and select the relevant tracks and to then open 'Batch rename".

    Can you help with the next step which I described above?

    Many thanks!!

    my code so far:

    var trackNames = sf.ui.proTools.trackNames.filter(n => n.match(/(Final|Gtr|Gt)/i));

    sf.ui.proTools.trackSelectByName({
    names: trackNames,
    deselectOthers: true,
    });

    sf.wait();

    //Calling command "Batch Rename" from package "Goetz Testers"
    sf.soundflow.runCommand({
    commandId: 'package:cl9fnv8lv0008zl10ytfuovda',
    props: {}
    });

    • 7 replies
    1. Brenden @nednednerb
        2022-10-20 22:47:48.745Z

        I have an idea of how you might derive the code or clues to it.

        Use the "regular" UI element click and type macros to find out how to insert the text strings.

        Then, which more confusing to me, insert your new name variable(s) manually and/or add to the variable created last time...

        I think actually UI-clicking to fill in the text is the less tricky part, and the more interesting part is the variable. Is it always "+1" in change? If so, that seems potentially doable with a clever variable addition before formulating the find & replace names.

        Instead of integer addition on the text field, maybe you could use the "numbering" option at the bottom of the Batch Rename dialog. Then you would just need "6m" in text and add numbering with no separator, starting at 1, two place values so the first two names would be 6m01 and 6m02 That might be a little simpler!

        1. samuel henriques @samuel_henriques
            2022-10-22 21:09:47.361Z

            Hello Goetz,
            Try this,

            /**
            * @param {string} find
            * @param {string} replace
            */
            function batchTrackRename(find, replace) {
            
                //Open batch track rename
                sf.keyboard.press({ keys: "alt+shift+r", fast: true });
            
                const batchTrackRenameWin = sf.ui.proTools.windows.whoseTitle.is('Batch Track Rename').first
                batchTrackRenameWin.elementWaitFor({ waitType: "Appear" }).element;
            
                const checkBoxWhoseTitle = batchTrackRenameWin.checkBoxes.whoseTitle
            
                checkBoxWhoseTitle.is('Replace').first.checkboxSet({ targetValue: "Enable" });
                checkBoxWhoseTitle.is('Clear Existing Name').first.checkboxSet({ targetValue: "Disable" });
                checkBoxWhoseTitle.is('Regular Expressions').first.checkboxSet({ targetValue: "Enable" });
                checkBoxWhoseTitle.is('Trim').first.checkboxSet({ targetValue: "Disable" });
                checkBoxWhoseTitle.is('Add').first.checkboxSet({ targetValue: "Disable" });
                checkBoxWhoseTitle.is('Numbering').first.checkboxSet({ targetValue: "Disable" });
                //Find
                batchTrackRenameWin.textFields.first.elementSetTextFieldWithAreaValue({ value: find });  //  Find
                //Replace
                batchTrackRenameWin.textFields.allItems[1].elementSetTextFieldWithAreaValue({ value: replace });  // Replace
                batchTrackRenameWin.buttons.whoseTitle.is('OK').first.elementClick();
                batchTrackRenameWin.elementWaitFor({ waitType: "Disappear" });
            };
            
            
            
            /**
            * @param {RegExp} match
            * @param {string[]} trackName
            */
            function getNewCueName(match, trackName) {
            
                const findCueName = trackName[0].match(match)[0]
                let firstNumber = +findCueName.split("m")[0]
                let secondNumber = +findCueName.split("m")[1]
                return `${firstNumber}m${++secondNumber}`
            
            };
            
            // Find match number+m+number
            const findRegex = /\d+[m]\d+/
            
            //Select track names including...
            const trackNamesToRename = sf.ui.proTools.trackNames.filter(n => n.match(/(Final|Gtr|Gt)/i));
            
            // new name incremented
            const newCueName = getNewCueName(findRegex, trackNamesToRename);
            
            // Select target tracks
            sf.ui.proTools.trackSelectByName({ names: trackNamesToRename, deselectOthers: true });
            
            // Rename target tracks
            batchTrackRename(findRegex.source, newCueName);
            
            1. samuel henriques @samuel_henriques
                2022-10-23 11:47:09.171Z

                This should should work as you asked for.
                But I'm thinking instead on taking the current track and increment, it should take the name from the session.
                So whatever you name the session, that's what you'll have in the tracks. Any discrepancy will be fixed.

                1. Hi Sam,

                  Many thanks for your help with this.
                  The code returns an error message for Line 37.

                  I think the use of the word 'cue' in my description was misleading. A 'cue' in film scoring is a piece of music which bears a number i.e. 6m36, which will be the same as the session name.

                  In the meantime, I managed to write a code which does the job, mainly just using key strokes to copy and paste the names.
                  I'm new to this, so it's not very slick, but it works:

                  Thanks for your help and best wishes,

                  Goetz B.

                  1. sf.ui.proTools.appActivateMainWindow();

                    sf.keyboard.press({
                    keys: "alt+shift+r",
                    });

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.checkBoxes.whoseTitle.is("Replace").first.elementWaitFor();

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[1].elementClick();

                    sf.keyboard.press({
                    keys: "cmd+a",
                    });

                    sf.keyboard.press({
                    keys: "cmd+c",
                    });

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.first.elementClick();

                    sf.keyboard.press({
                    keys: "cmd+a",
                    });

                    sf.keyboard.press({
                    keys: "backspace",
                    });

                    sf.keyboard.press({
                    keys: "cmd+v",
                    });

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementClick();

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementWaitFor({
                    waitType: "Disappear",
                    });

                    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename Error").first.buttons.whoseTitle.is("OK").first.elementClick();

                    sf.ui.proTools.menuClick({
                    menuPath: ["File","Save As..."],
                    });

                    sf.ui.proTools.windows.whoseTitle.is("Save").first.textFields.first.elementWaitFor();

                    sf.keyboard.press({
                    keys: "cmd+c",
                    });

                    1. sf.ui.proTools.windows.whoseTitle.is("Save").first.buttons.whoseTitle.is("Cancel").first.elementClick();

                      sf.ui.proTools.windows.whoseTitle.is("Save").first.buttons.whoseTitle.is("Cancel").first.elementWaitFor({
                      waitType: "Disappear",
                      });

                      sf.keyboard.press({
                      keys: "alt+shift+r",
                      });

                      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[1].elementWaitFor();

                      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[1].elementClick();

                      sf.keyboard.press({
                      keys: "cmd+v",
                      });

                      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementClick();

                      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementWaitFor({
                      waitType: "Disappear",
                      });

                      1. samuel henriques @samuel_henriques
                          2022-10-25 12:04:54.578Z

                          Could you check Kitch's vdeo on How to quote code in the SoundFlow forum. please.

                          It seams to be failing because the track name is not in the format you posted "ISS 6m36_Final_5.1_Stem 1 Orchestra 1"
                          Maybe doesn't have the "6m36" portion?
                          I can make it take this portion from the session name. would the session name be "6m36.ptx" only?