No internet connection
  1. Home
  2. How to

How to append text to clip name.

By Vidar Grande @vidar
    2019-03-08 15:15:55.397Z

    Hey, so i'm trying to make a script for appending a bit of text to the end of a clip name.
    It would be very useful for when i'm recording ADR or VO to be able to quickly mark the preferred take with "PREF" at the end.

    This is my script so far:

    sf.ui.proTools.menuClick({menuPath:['Clip', 'Rename...']});
    sf.keyboard.press({keys: 'right'});
    sf.keyboard.press({keys: 'space'});
    sf.keyboard.type({text : 'PREF'});
    sf.keyboard.type({keys: 'enter'});

    This doesn't work because it doesn't select the enter text box in the renaming widow before pressing the right arrow key.
    Does anyone know how to solve this?

    Thank you.

    Solved in post #2, click to view
    • 5 replies
    1. Christian Scheuer @chrscheuer2019-03-12 12:41:02.091Z2019-03-13 19:23:25.353Z

      Hi @vidar.
      Welcome to the forum and thank you for asking!

      Here's a script that will append ' PREF' to your clip name.
      Note we (almost) don't use the keyboard but we're setting the value of the Name text field directly in code. This makes it much more stable.

      function renameClip(callback) {
          //Make sure Pro Tools Edit Window is active
          sf.ui.proTools.appActivateMainWindow();
      
          //Make sure we have no search in Clips list - if we had, Clip Rename won't work (Pro Tools bug)
          sf.keyboard.press({ keys: 'cmd+shift+d' });
      
          //Clip Clip->Rename...
          sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
      
          //Wait for 'Name' dialog to come up, assign the dialog to dlg variable
          var dlg = sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor({}, 'Could not find "Name" dialog').element;
      
          //Find the first text field in the group with title 'Name'
          var textField = dlg.groups.whoseTitle.is('Name').first.textFields.first;
      
          //Get the current Name
          var currentName = textField.title.value || textField.value.value;
      
          //Make a variable with the new name, based on the old one by calling the callback function provided in the 1st argument
          var newName = callback(currentName);
      
          //Set the value of the textField
          textField.elementSetTextFieldWithAreaValue({ value: newName });
      
          //Press OK
          dlg.buttons.whoseTitle.is('OK').first.elementClick();
      
          //Wait for the dialog to close
          dlg.elementWaitFor({ waitForNoElement: true });
      }
      
      renameClip(function(oldName) {
          //Make the new name the oldName plus ' PREF'
          return oldName + ' PREF';
      });
      
      ReplySolution
      1. VVidar Grande @vidar
          2019-03-12 14:05:41.553Z

          Thanks for helping me out Christian!
          Very close, but it just renames the clip PREF it doesn't append it to the already existing name.
          Could it be something with the callback?

          Thank you,

          1. Hi Vidar. I think this may be because of the PT version I was testing on. Which PT version are you on?

            1. One guess is you should change these lines:

                  //Get the current Name
                  var currentName = textField.value.value;
              

              to

                  //Get the current Name
                  var currentName = textField.title.value;
              
              1. VVidar Grande @vidar
                  2019-03-13 08:41:23.515Z

                  Perfect!
                  I'm on 2018.12 and that solved it, Thank you!