No internet connection
  1. Home
  2. How to

Batch Clip Renamer: Setting Trim Value

By John Michael Caldwell @johnmcald
    2021-08-20 19:23:54.015Z

    Hi all, running into a road block trying to script the Batch Clip Renamer. No matter how I try to script it, I can't seem to set the value of the Trim from Beginning or Trim from End text feilds... Even if I try to use the Set Value of Text Area or Set Value of Text Field Area Actions it just doesn't seem to work. I also tried a workaround of selecting the text field and typing the number I wanted to trim but it doesn't reliably enter the number, sometimes only inserting the number into the end of the text field instead of replacing the contents of the text field...

    Here is my script. I'm sure whatever it is it's glaringly obvious to someone who knows what they're doing...

    Thanks,

    
    sf.ui.proTools.appActivate();
    sf.ui.proTools.appActivateMainWindow();
    
    let trimEnd = (prompt('Characters to trim from end:', '3'));
    
    let ptxName = sf.ui.proTools.focusedWindow.title.invalidate().value.replace(/^\w+\W\s/g, "");
    let prefixName = (prompt('Prefix:', ptxName.toString()));
    
    sf.keyboard.press({
        keys: "ctrl+shift+r",
    });
    
    let win = sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename')
    
    win.first.elementWaitFor();
    
    //Batch Clip Rename: Replace
    win.first.checkBoxes.whoseTitle.is("Replace").first.checkboxSet({
        targetValue: "Disable",
    });
    
    //Batch Clip Rename: Trim
    win.first.checkBoxes.whoseTitle.is("Trim").first.checkboxSet({
        targetValue: "Enable",
    });
    win.first.textFields.whoseTitle.is("").allItems[2].elementSetTextFieldWithAreaValue({
        value: '0',
    });
    win.first.textFields.whoseTitle.is("").allItems[3].elementSetTextFieldWithAreaValue({
        value: trimEnd.toString(),
    });
    
    //Batch Clip Rename: Add
    win.first.checkBoxes.whoseTitle.is("Add").first.checkboxSet({
        targetValue: "Enable",
    });
    win.first.checkBoxes.whoseTitle.is("Prefix:").first.checkboxSet({
        targetValue: "Enable",
    });
    win.first.textFields.whoseTitle.is("").allItems[6].elementSetTextFieldWithAreaValue({
        value: prefixName,
    });
    win.first.checkBoxes.whoseTitle.is("Insert:").first.checkboxSet({
        targetValue: "Disable",
    });
    win.first.checkBoxes.whoseTitle.is("Suffix:").first.checkboxSet({
        targetValue: "Disable",
    });
    
    //Batch Clip Rename: Numbering
    win.first.checkBoxes.whoseTitle.is("Numbering").first.checkboxSet({
        targetValue: "Disable",
    });
    
    //Batch Clip Rename: Process Order
    win.first.radioButtons.whoseTitle.is("Clips List Sort Order").first.elementClick();
    
    
    win.first.buttons.whoseTitle.is("OK").first.elementClick();
    
    
    Solved in post #2, click to view
    • 10 replies

    There are 10 replies. Estimated reading time: 22 minutes

    1. samuel henriques @samuel_henriques
        2021-08-20 20:05:07.661Z

        Hello @johnmcald,

        some text fields decided to be annoying, this works for me.

        sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[2].elementSetTextFieldWithAreaValue({value:"5", useMouseKeyboard:true});
        
        sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[3].elementSetTextFieldWithAreaValue({value:"5",useMouseKeyboard:true});
        
        ReplySolution
        1. JJohn Michael Caldwell @johnmcald
            2021-08-20 21:01:12.089Z

            Ah, that works well. Thanks @samuel_henriques.

          • H
            In reply tojohnmcald:
            Houston Snyder @Houston_Snyder
              2021-08-21 18:02:08.825Z

              Hey there!

              Maybe you guys can help me out?

              I'm trying to make a little script to help with VO editing. I took the code you pasted above and modified it a little to work for me. But, the road block i'm running into is that the "auto-name seperated clips" preference seems to prevent it from working well. Basically, the auto naming makes it hard to determin how many digits to trim from the end. Is there a way to incorporate something into the script that removes any suffix's PT adds to clips? For example, just before batch rename is openend, it renames the clip to remove "-01" or "-100" from the end? So I guess I need a way to remove everything from the end to the "-".

              The general format we use for naming looks like this "SN_103_SCXX_chracter_tkXX_LNXXX"
              SN - show name abreiviation
              103 - episode number
              SCX - Scene number where XX is replaced with the scene number
              character - the characters name
              tkXX - take number where XX is replaced with the take number
              LNXXX - Line number where XXX is replaced with the line number.

              Thanks for any insights!!

              sf.ui.proTools.appActivate();
              sf.ui.proTools.appActivateMainWindow();
              
              let suffixName = (prompt('Line Number', ''));
              let replaceName = (prompt('Take Number', ''));
              
              sf.keyboard.press({
                  keys: "b",
                  fast: true,
              });
              
              sf.keyboard.press({
                  keys: "cmd+c",
                  fast: true,
              });
              
              sf.keyboard.press({
                  keys: "semicolon",
                  fast: true,
              });
              
              sf.keyboard.press({
                  keys: "cmd+v",
                  fast: true,
              });
              
              sf.keyboard.press({
                  keys: "ctrl+shift+r",
              });
              
              let win = sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename')
              
              win.first.elementWaitFor();
              
              //Batch Clip Rename: Replace
              win.first.checkBoxes.whoseTitle.is("Replace").first.checkboxSet({
                  targetValue: "Enable",
              });
              sf.ui.proTools.windows.whoseTitle.is("Batch Clip Rename").first.textFields.allItems[0].elementSetTextFieldWithAreaValue({value:"XX", useMouseKeyboard:false
              });
              sf.ui.proTools.windows.whoseTitle.is("Batch Clip Rename").first.textFields.allItems[1].elementSetTextFieldWithAreaValue({value:replaceName.toString(), useMouseKeyboard:false
              });
              
              //Batch Clip Rename: Trim
              win.first.checkBoxes.whoseTitle.is("Trim").first.checkboxSet({
                  targetValue: "Enable",
              });
              sf.ui.proTools.windows.whoseTitle.is("Batch Clip Rename").first.textFields.allItems[2].elementSetTextFieldWithAreaValue({value:"0", useMouseKeyboard:true
              });
              sf.ui.proTools.windows.whoseTitle.is("Batch Clip Rename").first.textFields.allItems[3].elementSetTextFieldWithAreaValue({value:"3", useMouseKeyboard:true
              });
              
              
              //Batch Clip Rename: Add
              win.first.checkBoxes.whoseTitle.is("Add").first.checkboxSet({
                  targetValue: "Enable",
              });
              win.first.checkBoxes.whoseTitle.is("Prefix:").first.checkboxSet({
                  targetValue: "Disable",
              });
              win.first.checkBoxes.whoseTitle.is("Insert:").first.checkboxSet({
                  targetValue: "Disable",
              });
              win.first.checkBoxes.whoseTitle.is("Suffix:").first.checkboxSet({
                  targetValue: "Enable",
              });
              sf.ui.proTools.windows.whoseTitle.is("Batch Clip Rename").first.textFields.allItems[9].elementSetTextFieldWithAreaValue({value:suffixName.toString(), useMouseKeyboard:false
              });
              
              //Batch Clip Rename: Numbering
              win.first.checkBoxes.whoseTitle.is("Numbering").first.checkboxSet({
                  targetValue: "Disable",
              });
              
              //Batch Clip Rename: Process Order
              win.first.radioButtons.whoseTitle.is("Clips List Sort Order").first.elementClick();
              
              
              win.first.buttons.whoseTitle.is("OK").first.elementClick();
              
              1. JJohn Michael Caldwell @johnmcald
                  2021-08-21 20:49:06.958Z

                  Hi @Houston_Snyder,
                  So, you're manually inputting the take number and the line number from prompts and then using the Batch Clip Renamer to rename them?

                  I do see a potential issue if you're only inputting the take number "XX" and not "tkXX" then you might end up replacing numbers in multiple places. Say, if the Scene number is 12 and the take number is 12 the Batch Clip Renamer won't know the difference and will replace all iterations of 12 with whatever number you're trying to replace it with. But maybe I'm misunderstanding exactly what's going on.

                  So, I think one thing to do would be to replace the "tk" as well as the number that's after it.

                  You could also start your script by setting the clip name to a variable and then finding the elements of the script you want to replace with your prompted variables, I think...

                  Here's a solution to getting the selected clip name: Get selected Clip Name

                  That script might return something like this: "SN_103_SC56_Bilbo Baggins_tk102_LN646-004" right?

                  Then you could go about replacing elements in the name, so something like this, maybe:

                  
                  function getSelectedClipNamesFromClipList() {
                      const clipsTable = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first;
                  
                      // Get all selected clips
                      const selectedClips = clipsTable.children.whoseRole.is("AXRow").allItems.map(row =>
                          row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. '));
                  
                      // Extract clip names
                      const clipNames = selectedClips.map(c => c.split('"')[1]);
                  
                      return clipNames
                  };
                  
                  const selectedClip = getSelectedClipNamesFromClipList()[0];
                  
                  let lnNum = (prompt('Line Number', ''));
                  let tkNum = (prompt('Take Number', ''));
                  
                  let trimName = selectedClip.replace(/-\d+$/gm, "");
                  let newTkName = trimName.replace(/tk\d+/g, tkNum.toString());
                  let newName = newTkName.replace(/LN\d+/g, lnNum.toString());
                  
                  log(newName)
                  
                  

                  Then you can enable the replace clip name section and set the newName variable to replace the selectedClip variable, I think?

                  What's the exact sequence of the renaming process? Maybe you could even automate the line and take numbers to be increased instead of being prompted at the beginning of the script?

                  There might be a more consolidated way of doing the renaming portion I'm doing but that's the best I can think of right now. I'm also not in front of Pro Tools right now to test if this is working the way I think it is.

                  1. HHouston Snyder @Houston_Snyder
                      2021-08-22 13:18:42.890Z

                      Thanks, John!

                      This is super helpful!

                      So a couple updates. I changed the format of the naming to be a little more conducive to managing things in the clip window. So, i'm now operating with the below:
                      SN_101_SCXX_Character_LNXXX_TKXX

                      Basically I swapped LineNumber and TakeNumber.

                      The code you provided makes more sense. If I understand it correctly it bypasses the Batch Clip Rename window?

                      Anyway, I ran it and wasn't getting the exact results I needed. I tried playing around with it a little bit so that it can change the SceneNumber, LineNumber, and TakeNumber in that order. But, i'm getting strange results. Probably because I have no idea what i'm doing.

                      Ultimately the full process is below:
                      -Make cursor selection from raw VO track.
                      -Cut clip and move to track below
                      -prompt for SceneNumber, LineNumber, TakeNumber.
                      -remembers previous input
                      -cancel button aborts process entirely
                      -rename file
                      -remove any protools auto generated naming for "separated clips"

                      Here is what I start with and what I get after running the code.
                      -start with "SN_101_SC00_Character_LN000_TK00-045"
                      -run code and get prompted for "Scene Number" (I enter 01) , "Line Number" (I enter 002), and "Take Number" (I enter 03).
                      -what I get back in the log is "SN_101_01_Character_LN000_TK00"

                      So, it successfully removes the auto generated separated clip name, which is super cool!
                      But, it does not seem to change the Line Number or Take Number.
                      Strangely, it changes the Scene Number, but removes the "SC"

                      Anyway, I really appreciate all your help so far and if you have any more thoughts, its super appreciated. I owe you a beer!

                      Here's my code so far.

                          const clipsTable = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first;
                      
                          // Get all selected clips
                          const selectedClips = clipsTable.children.whoseRole.is("AXRow").allItems.map(row =>
                              row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. '));
                      
                          // Extract clip names
                          const clipNames = selectedClips.map(c => c.split('"')[1]);
                      
                          return clipNames
                      };
                      
                      const selectedClip = getSelectedClipNamesFromClipList()[0];
                      
                      let scNum = (prompt( 'Scene Number', ''));
                      let lnNum = (prompt('Line Number', ''));
                      let tkNum = (prompt('Take Number', ''));
                      
                      let trimName = selectedClip.replace(/-\d+$/gm, "");
                      let newScName = trimName.replace(/SC\d+/g, scNum.toString());
                      let newLnName = newScName.replace(/LN\d+/g, lnNum.toString());
                      let newTkName = newLnName.replace(/TK\d+/g, tkNum.toString());
                      
                      log(newScName)```
                      1. JJohn Michael Caldwell @johnmcald
                          2021-08-22 23:17:27.383Z

                          Here's a quick question... Are you trying to fully automate the process or name each clip individually? Is there a reason to use the Batch Clip Renamer?

                          Also, question number 2: Are you only need to rename the audio clip name? Confirming that you're not also trying to name the audio clip's disk file name (i.e. Finder has the same name as it is in Pro Tools.)

                          I've adjusted the process a bit based off of how I understand you're doing things a little more... This is a full code that will do the entire process of prompting you and renaming the clip.

                          This does not rename the disk file; so when you navigate to the clip's file in Finder you won't see the same name as you see in Pro Tools.

                          I wonder if there's a better way to automate the numbering sequence instead of inputting the numbers for each clip? I'm not certain of your workflow so I'm really not sure, but if there's a way for the script to grab the current Scene Number, Line Number, and last Take number then maybe you wouldn't have to input as much information each time you rename the clip?

                          Depending on how fast this process is it might even be worth having a separate script for update the Scene number into a global state variable and possibly the line number as well? Then all you would need to do is input the take number as maybe it's possible for that to be update automatically as well.

                          sf.ui.proTools.appActivate();
                          sf.ui.proTools.appActivateMainWindow();
                          
                          sf.keyboard.press({
                              keys: "shift+cmd+r",
                          });
                          
                          let win = sf.ui.proTools.windows.whoseTitle.is("Name")
                          
                          win.first.elementWaitFor();
                          
                          let selectedClip = win.first.groups.whoseTitle.is("Name").first.textFields.whoseTitle.is("").first.value.invalidate().value;
                          
                          let scNum = (prompt('Scene Number', ''));
                          let lnNum = (prompt('Line Number', ''));
                          let tkNum = (prompt('Take Number', ''));
                          
                          let trimName = selectedClip.replace(/-\d+$/gm, "");
                          let newScName = trimName.replace(/SC\d+/g, "SC" + scNum.toString());
                          let newLnName = newScName.replace(/LN\d+/g, "LN" + lnNum.toString());
                          let newTkName = newLnName.replace(/TK\d+/g, "TK" + tkNum.toString());
                          
                          let newName = newTkName.toString();
                          
                          sf.keyboard.press({
                              keys: "cmd+a",
                          });
                          sf.keyboard.press({
                              keys: "backspace",
                          });
                          
                          win.first.groups.whoseTitle.is("Name").first.textFields.whoseTitle.is("").first.elementSetTextFieldWithAreaValue({
                              value: newName,
                              useMouseKeyboard:true
                          });
                          
                          win.first.buttons.whoseTitle.is("OK").first.elementClick();
                          
                          
                          1. HHouston Snyder @Houston_Snyder
                              2021-08-23 15:43:22.377Z

                              Hey John,

                              Thanks again so much for your help. I really appreciate it!

                              So before I jump in to the workflow. I ran the code you provided and it seems to leave me a new clip name that is stripped of the auto generated clip name, however has not replaced the XXX or XX with the relevant prompts.
                              For example:
                              Clip name starts with "SN_101_SCXX_Character_LNXXX_TKXX-27"
                              Script runs
                              Name window opens
                              Scene Number Prompt: 01
                              Line Number Prompt: 002
                              Take Number Prompt: 03
                              The script removes "SN_101_SCXX_Character_LNXXX_TKXX-27" from the name window and replaces it with "SG_103_SCXX_Herman_LNXXX_TKXX"
                              Name Window closes.

                              Let me know if i'm missing something on my end!
                              I'm running PT 2021.7.0 in Big Sur

                              I do eventually want to fully automate the process!

                              Ultimately, I want to get to a point where it is smart enough to self name based off info I drop in Markers. I'd like to be able to drop a marker at the top of a take (while recording) that is the line number (001) then another marker at the end of the take thats labeled (END). For each take I repeat the process. Once the recording is finished, I can then run the edit script and it looks at each line number and selects to the next marker labeled (END) - cuts that clip and drops it down to a new track. Then jumps to the next line number (002) and selects to the next marker labeled (END) and repeats the process over and over.

                              At that point I then have all the edited clips and could run a script that looks at the marker data to name the line numbers. But a lot could happen in a record that maybe makes that scenario not so straight forward.

                              So, for now, i'm trying to create a script that allows me to make a selection and quickly name the clip based on prompts. Maybe their is a middle ground where it has a toggle switch that enables the batch clip renamer's ability to automatically increase the take number if say I select 10 clips that are all the same Scene Number and Line Number.

                              Let me know if you have any ideas. Thanks for all your help!

                              1. JJohn Michael Caldwell @johnmcald
                                  2021-08-23 19:05:51.092Z

                                  I'm a little confused about what is happening. The script seems to be working for me.

                                  Clip before:

                                  Clip after:

                                  I'm curious where it's changing the "SN" at the beginning to "SG" and stripping the number after it? Or adding the SC number to the SN?

                                  What are you entering into the prompts? Could that be an issue? When I'm entering into the prompt I'm only adding the number; so for "Scene number" prompt I'm entering "103" and same for LN and TK numbers.

                                  I'm not on Big Sur... but I am on Pro Tools 2021.6 and SoundFlow 4.3.5. I don't necessarily see that being the issue though since this script is basically doing all of the text formatting with the script and copying and pasting into the Name window text field area.

                                  1. HHouston Snyder @Houston_Snyder
                                      2021-08-24 13:43:33.408Z

                                      @johnmcald

                                      So sorry! I just realized my issue. I was using XXX and XX in place of 000 and 00. Once I changed the clip name to 000, 00 it worked perfectly!

                                      They issue with changing from SG to SN was a typo!

                                      This is so brilliant! I'm so greatful!

                                      One cool thing I just tested is it seems like you can switch the place of TK and LN in the orignal clip name and it still corrects the new name with the correct prompts. So, if we decide to do "SN_101_SC00_Character_TK00_LN000" instead of "SN_101_SC00_Character_LN000_TK00" it still puts the data in the correct place! Sometimes we change the order based on how we might want things sorted in the clip window.

                                      Next, If I wanted to have the "Cancel" button abort the script and close the "Name" window. Would I start with replacing
                                      let scNum = (prompt('Scene Number', ''));
                                      With

                                          title: 'VO Edit',
                                          prompt: 'Scene Number',
                                          buttons: ["Cancel", 'Enter'],
                                          defaultAnswer: "",
                                          defaultButton: 'Enter',
                                          onCancel: 'Abort'
                                      })
                                      
                                      1. JJohn Michael Caldwell @johnmcald
                                          2021-08-24 20:22:29.806Z

                                          Prefect. Glad it's working for you, and yes! Start adding some of you own things to it.

                                          As is, when cancelling, the script won't finish running and the Name window is left open.