No internet connection
  1. Home
  2. How to

Batch Rename - remove .cm

By Scott Smith @Scott_Smith
    2021-12-21 21:23:29.098Z

    Hi All,
    I'm trying to create a script that will batch rename selected clips with a specifc set of paramaters. I would like to remove ".cm" after committing a file. I've got a preset saved in Batch Rename that Finds ".cm" and replaces it with nothing. This works just fine but I can't quite figure out the code I'm missing to complete the operation. I can get to the window but thats as far as I can get it. Current code thus far:

    sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is('Clip List').first.popupMenuSelect({
    menuPath: ["Batch Rename..."],
    });

    sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename').first.elementWaitFor();

    sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename').first.textFields.whoseTitle.is('').allItems[6].elementClick();

    Thanks so much!

    • 13 replies
    1. samuel henriques @samuel_henriques
        2021-12-22 13:05:53.224Z2021-12-24 17:43:00.808Z

        Hello Scott Smith,

        try this:

        /**
        * @param {string} find
        * @param {string} replace
        */
        function batchTrackRenameWinOptions(find, replace) {
        
            sf.keyboard.press({ keys: "alt+shift+r", fast: true });
        
            const batchTrackRenameWin = sf.ui.proTools.windows.whoseTitle.is('Batch Track Rename').first.elementWaitFor({}).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: "Disable" });
            checkBoxWhoseTitle.is('Trim').first.checkboxSet({ targetValue: "Disable" });
            checkBoxWhoseTitle.is('Add').first.checkboxSet({ targetValue: "Disable" });
            checkBoxWhoseTitle.is('Numbering').first.checkboxSet({ targetValue: "Disable" });
        
            //  Find
            batchTrackRenameWin.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: find });
            // Replace
            batchTrackRenameWin.textFields.whoseTitle.is('').allItems[1].elementSetTextFieldWithAreaValue({ value: replace });
        
            batchTrackRenameWin.buttons.whoseTitle.is('OK').first.elementClick();
        
            batchTrackRenameWin.elementWaitFor({ waitType: "Disappear" });
        }
        
        sf.ui.proTools.appActivateMainWindow()
        sf.ui.proTools.invalidate()
        
        batchTrackRenameWinOptions(".cm", "")
        
        1. SScott Smith @Scott_Smith
            2021-12-24 17:07:22.200Z

            Thanks Samuel
            Im getting the following error, sureley its something I'm doing wrong:

            "Could not open popup menu (.cm rename: Line 1)
            popupMenu.open.fromElement requires an element"

            The script I'm currently using is the one I originally sent with yours added on. This may be incorrect. If I use only what you sent I get a different error:

            "Element was not found or removed after waiting 2000 ms (.cm rename: Line 9)"

            Thanks so much for your help!

            1. samuel henriques @samuel_henriques
                2021-12-24 17:22:21.703Z

                The one I sent should do it all.

                Could you send me a screen recording so I can see it please?

                1. SScott Smith @Scott_Smith
                    2021-12-24 17:35:39.862Z

                    Here you go! Couldnt work out how to send an actual video. Thanks!

                    1. samuel henriques @samuel_henriques
                        2021-12-24 17:37:04.015Z

                        you can send a dropbox link with the video

                        1. SScott Smith @Scott_Smith
                            2021-12-24 17:39:45.981Z
                            1. samuel henriques @samuel_henriques
                                2021-12-24 17:42:28.416Z

                                I'm sorry, it fails because you are running outside protools. Try with a shortcut trigger.
                                I'll write a bit to activate pro tools first, just a moment.

                                1. samuel henriques @samuel_henriques
                                    2021-12-24 17:43:59.596Z

                                    Just updated with a line to activate pro tools. This way it will work if you run it with any other application active.

                                    1. SScott Smith @Scott_Smith
                                        2021-12-24 17:52:29.362Z

                                        Thanks Samuel,
                                        When I have PT open and trigger it from the stream deck it works. Only issue is this is batch track rename. I'm looking for Batch Clip Rename ;)

                                        Thanks for all your help!

                                        1. samuel henriques @samuel_henriques
                                            2021-12-24 17:56:26.699Z

                                            ahhhhh. okok just a moment

                                            1. samuel henriques @samuel_henriques
                                                2021-12-24 18:23:09.564Z

                                                Here you go.

                                                I changed the find/replace to a regular expression so it will only find the match from the end of the name. ( Very unlikely you would have .cm in the middle of a clip name but...)

                                                Hope this is it

                                                /**
                                                * @param {string} find
                                                * @param {string} replace
                                                */
                                                function batchClipRenameWinOptions(find, replace) {
                                                
                                                
                                                    sf.ui.proTools.menuClick({ menuPath: ["View", "Other Displays", "Clip List"], targetValue: "Enable" })
                                                
                                                    sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is("Clip List").first.popupMenuSelect({
                                                        menuPath: ["Batch Rename..."],
                                                    });
                                                
                                                    const batchClipRenameWin = sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename').first.elementWaitFor({}, 'Bach Rename Window failed to open \nCheck clip selection.').element;
                                                
                                                    const checkBoxWhoseTitle = batchClipRenameWin.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: "Disable" });
                                                    checkBoxWhoseTitle.is('Trim').first.checkboxSet({ targetValue: "Disable" });
                                                    checkBoxWhoseTitle.is('Add').first.checkboxSet({ targetValue: "Disable" });
                                                    checkBoxWhoseTitle.is('Numbering').first.checkboxSet({ targetValue: "Disable" });
                                                
                                                    checkBoxWhoseTitle.is("Regular Expressions").first.checkboxSet({ targetValue: "Enable" });
                                                
                                                    //  Find
                                                    batchClipRenameWin.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: find });
                                                    // Replace
                                                    batchClipRenameWin.textFields.whoseTitle.is('').allItems[1].elementSetTextFieldWithAreaValue({ value: replace });
                                                
                                                    batchClipRenameWin.buttons.whoseTitle.is('OK').first.elementClick();
                                                
                                                    batchClipRenameWin.elementWaitFor({ waitType: "Disappear" });
                                                }
                                                
                                                sf.ui.proTools.appActivateMainWindow()
                                                sf.ui.proTools.invalidate()
                                                
                                                
                                                //  $ will match .cm from end of name
                                                batchClipRenameWinOptions(".cm$", "")
                                                
                                                1. SScott Smith @Scott_Smith
                                                    2021-12-24 18:35:46.908Z

                                                    This works perfectly. Thank you so much Samuel for taking the time. Much appreciated, you've just saved me a ton of time. Happy Holidays and all the best for the New Year

                                                    1. samuel henriques @samuel_henriques
                                                        2021-12-24 18:43:09.929Z

                                                        Awesome. Happy holidays to you too!!