No internet connection
  1. Home
  2. Macro and Script Help

Batch Rename Script Fix Help

By Jocelyn Scofield @Jocelyn_Scofield
    2023-10-05 01:01:40.258Z

    Title

    Batch Rename Script Fix Help

    What do you expect to happen when you run the script/macro?

    Hello, I am trying to automate a batch rename that gets rid of the title and renames with a Prefix and then adds the clip numbers to the end. XXXm01, XXXm02, XXXm03. This is as far as I've gotten. I am getting an error "Batch Rename Falied - Element was not found or removed after waiting 2000ms (Batch Rename: Line 14)"

    I started with this script and have been trying to modify it. I am unable to find the macro that lets you ask for data, so I copy and pasted it from this script. batch rename script question #post-4

    Would appreicate fixes. Thank you!

    Are you seeing an error?

    Batch Rename Failed Element was not found or removed after waiting 2000ms (Batch Rename: Line 14)

    What happens when you run this script?

    I get the error and but it does not change the name at all.

    How were you running this script?

    I clicked the "Run Script" or "Run Macro" button in SoundFlow

    How important is this issue to you?

    3

    Details

    {
        "inputExpected": "Hello, \nI am trying to automate a batch rename that gets rid of the title and renames with a Prefix and then adds the clip numbers to the end. XXXm01, XXXm02, XXXm03. This is as far as I've gotten. I am getting an error \"Batch Rename Falied - Element was not found or removed after waiting 2000ms (Batch Rename: Line 14)\" \n\nI started with this script and have been trying to modify it. I am unable to find the macro that lets you ask for data, so I copy and pasted it from this script. https://forum.soundflow.org/-6910#post-4\n\nWould appreicate fixes. Thank you!",
        "inputIsError": true,
        "inputError": "Batch Rename Failed\nElement was not found or removed after waiting 2000ms (Batch Rename: Line 14)",
        "inputWhatHappens": "I get the error and but it does not change the name at all. ",
        "inputHowRun": {
            "key": "-MpfwYA4I6GGlXgvp5j1",
            "title": "I clicked the \"Run Script\" or \"Run Macro\" button in SoundFlow"
        },
        "inputImportance": 3,
        "inputTitle": "Batch Rename Script Fix Help"
    }

    Source

    // Identify Batch Track Rename window
    const batchTrackRenameWin = sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first;
    
    // Make Sure Pro Tools is being listened to.
    sf.ui.proTools.appActivateMainWindow();
    
    // First, ask the user for their Prefix
    var prefixtext = prompt(`What's the Prefix?`);
    
    // Launch Batch Track Rename
    sf.keyboard.press({ keys: "alt+shift+3",});
    
    // Wait for Batch Track Rename to appear
    batchTrackRenameWin.elementWaitFor();
    
    // Click on Clear Existing Name
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.checkBoxes.whoseTitle.is("Clear Existing Name").first.elementClick();
    
    // Click on Prefix Box
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[6].elementClick();
    
    // Enter text from dialog box into the Prefix
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.allItems[9].elementSetTextFieldWithAreaValue({value:prefixtext});
    
    // Select Numbering
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.checkBoxes.whoseTitle.is("Numbering").first.elementClick();
    
    // Click on Starting Number
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.textFields.whoseValue.is("1").first.elementClick();
    
    // Ask the user for their input
    var startingnumber = prompt(`What's the Starting Number?`);
    
    // Enter text from Starting Number
    sf.keyboard.type(startingnumber);
    
    // Click 'Ok' to Perform Rename
    sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementClick();
    
    

    Links

    User UID: qUwpjOeyrgMDcEnorQvId9ZScgD2

    Feedback Key: sffeedback:qUwpjOeyrgMDcEnorQvId9ZScgD2:-NfxLgbjO5VfR5giGtD2

    Feedback ZIP: 35q9QQI8uKnJS34mkfSQdK27FufxUrBcPfxgmbcHxU4Uq28hXBcMRsHhPX8KMKFzqT4JE7wYgtanA+jY/zuYEp2PO8DftxWzptA6VccAlv5oLYtRhFJuRvuqkx09ZgxBDmp0HFQTfOmbo4QO58ZcAJk3G2C7BcMZXQn4SkyBSUqCL721H8e9xcDm4wY8Pf59v3/sqPCSfQSDSy86twXOCnZDWoQr4QMuntHt0K6HR8xeq4waa9YZEUcXrlXaUJTFv/hDVAPes1BujuOj3N/rzVx3gAfmyP8G8bwSFxLIkXyMKe6OjirHKpYgTPy+S4tWyYJ6MZNYEyoq6CPXmf3U6SKRcyruH9npwOspnIfnqZg=

    • 3 replies
    1. Raphael Sepulveda @raphaelsepulveda2023-10-05 16:12:14.305Z2023-10-05 23:59:47.598Z

      @Jocelyn_Scofield, there were a couple of issues here with the main one being that the shortcut to open the Batch Track Rename was incorrect—the one in your script is the one to consolidate. That is why you were getting that error since the window never comes up.

      I made a few adjustments to get this going.

      As a rule of thumb, it's good to prompt the user for input at the beginning of the script, that way once things are going the script doesn't get interrupted and cause possible errors.

      Give it a shot!

      // Ask the user for their Prefix
      const prefix = prompt(`What's the Prefix?`);
      
      // Ask the user for their input
      const startingNumber = prompt(`What's the Starting Number?`);
      
      const NUMBER_OF_PLACES = "2"; // Numbers in this format 01, 02, 03
      
      // Identify Batch Track Rename window
      const batchTrackRenameWin = sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first;
      
      // Make sure the Pro Tools Edit window is active
      sf.ui.proTools.appActivateMainWindow();
      
      // Launch Batch Track Rename
      sf.keyboard.press({ keys: "alt+shift+r" });
      
      // Wait for Batch Track Rename to appear
      batchTrackRenameWin.elementWaitFor();
      
      // Select Preset 1 to set everything in the window to default (assuming Preset 1 hasn't been set to something else)
      batchTrackRenameWin.buttons.whoseTitle.is("Preset Toggle 1").first.elementClick();
      
      // Click on Clear Existing Name
      batchTrackRenameWin.checkBoxes.whoseTitle.is("Clear Existing Name").first.checkboxSet({ targetValue: "Enable" });
      
      // Enter text from dialog box into the Prefix
      batchTrackRenameWin.textFields.allItems[6].elementSetTextFieldWithAreaValue({ value: prefix });
      
      // Select Numbering
      batchTrackRenameWin.checkBoxes.whoseTitle.is("Numbering").first.checkboxSet({ targetValue: "Enable" });
      
      // Enter text from Starting Number
      batchTrackRenameWin.textFields.allItems[11].elementSetTextFieldWithAreaValue({ value: startingNumber, useMouseKeyboard: true });
      
      // Set "Number of Places"
      batchTrackRenameWin.textFields.allItems[12].elementSetTextFieldWithAreaValue({ value: NUMBER_OF_PLACES, useMouseKeyboard: true });
      
      // Disable "Separate With" checkbox
      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.checkBoxes.whoseTitle.is("Separate With:").first.checkboxSet({ targetValue: "Disable" });
      
      // Click 'Ok' to Perform Rename
      sf.ui.proTools.windows.whoseTitle.is("Batch Track Rename").first.buttons.whoseTitle.is("OK").first.elementClick();
      
      1. JJocelyn Scofield @Jocelyn_Scofield
          2023-10-05 21:33:41.506Z

          Hi Raphael,
          Thank you so much. When I use this script, nothing happens. It asks me for the prefix and starting number but the file names remain unchanged.

          I thought maybe it had to do with leftover parameters. When I batch rename, sometimes there are parameters from the last batch rename. Maybe the script should have a clearing out of existing parameters. After I run the script, the starting number and Prefix remain parameters in Batch Track Rename box when I open it again. That might be an issue if I am need to run several batch renames.

          Hmm. Am I asking for a very hard

          1. I think you're right. Here's a simple way to go around that.

            I updated the script above to first select Preset 1 before setting the window up. Preset 1, by default, will init the window to default settings, but that's under the assumption that you have not overwritten it with other settings.

            This is the preset I'm talking about:

            Let me know if that works out for you.