No internet connection
  1. Home
  2. How to

Pro Tools, copy name from region to track

By Tor Bach Kristensen @Tor_Bach_Kristensen
    2020-12-09 14:04:27.885Z

    Hi.

    Is there a way to mark a region, and then have the name of that region be copied to the name of the corresponding track? I can't figure out how to build such a macro.

    • 27 replies

    There are 27 replies. Estimated reading time: 12 minutes

    1. Hey Tor!

      The following script will grab the name of the selected clip and rename the selected track.
      Let me know if that works for ya!

      const clipRenameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first;
      
      sf.ui.proTools.appActivateMainWindow();
      
      // Get name from clip
      sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
      clipRenameWin.elementWaitFor({ waitType: "Appear", }, 'Make sure a clip is selected');
      let clipName = clipRenameWin.groups.whoseTitle.is('Name').first.textFields.first.value.invalidate().value;
      clipRenameWin.buttons.whoseTitle.is('OK').first.elementClick();
      clipRenameWin.elementWaitFor({ waitType: "Disappear", });
      
      // Rename selected track
      sf.ui.proTools.selectedTrack.trackRename({ newName: clipName });
      
      1. T

        Yeah, it kind of works. Though it takes the name in the clip list, preferably it would be the name from any region marked in the arranged window :) And getting this error most of the times:

        Could not complete the Rename Selected Audio Clips command because Assertion in "/Volumes/Development/protools/release/2020/r3/ProTools/NewFileLibs/AFnd/Stems/AFnd_StemFormat.cpp", line 722.

        1. Oh no!

          Maybe I'm misunderstanding something. Could you explain in a bit more detail what you would like the script to do? What do you mean exactly when you say "mark a region"?

          1. M
            Michael Bouska @Michael_Bouska
              2021-02-28 06:24:10.342Z

              Im getting this error too. I think its because pro tools is trying to rename the Clip AND disk file. I think if you select "Name clip Only" in the clip rename dialog window, you won't get the error, but I have no idea how to add that to this script code haha

              1. Dustin Harris @Dustin_Harris
                  2021-02-28 15:11:57.384Z

                  Try changing

                  clipRenameWin.buttons.whoseTitle.is('OK').first.elementClick();
                  

                  To

                  clipRenameWin.buttons.whoseTitle.is('cancel').first.elementClick();
                  

                  And see if that fixes it. I’m on my phone at the moment so I can look into multiple tracks later on (unless Raphael beats me to it)

                  1. Thanks, @Dustin_Harris ! I’m away from my studio this weekend so feel free to do so!

                    1. Dustin Harris @Dustin_Harris
                        2021-02-28 15:42:42.563Z

                        Nice dude, enjoy! (And challenge accepted)

                  2. M
                    Michael Bouska @Michael_Bouska
                      2021-02-28 06:29:49.609Z

                      Also, if this code could be made to rename multiple selected tracks at once that would be amazing!

                      1. Dustin Harris @Dustin_Harris
                          2021-02-28 16:30:08.552Z2023-06-23 14:03:34.181Z

                          Try this and let me know how it goes:

                          const clearFind = () => sf.keyboard.press({ keys: "cmd+shift+d", }, `error in clearFind()`);
                          
                          function getCurrentClipName() { //This gets the current region name in Pro Tools
                              const clipNameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first
                              
                              try {
                                  clearFind();
                                  sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
                                  clipNameWin.elementWaitFor({}, `could not find rename window`);
                                  let currentClipName = clipNameWin.groups.whoseTitle.is('Name').first.textFields.first.value.invalidate().value;
                                  clipNameWin.buttons.whoseTitle.is('Cancel').first.elementClick({}, `could not click Rename window: cancel button`);
                                  return currentClipName
                              
                              } catch (err) {
                                  throw `error in getCurrentClipNameWin(): ${err}`
                              }
                          }
                          
                          
                          /**
                          * @param {string} clipName
                          */
                          function renameTrackFromClipName(clipName) {
                              sf.ui.proTools.selectedTrack.trackRename({ newName: clipName }, `could not rename track to "${clipName}"`);
                          }
                          
                          
                          function main() {
                              try {
                                  sf.ui.proTools.appActivateMainWindow();
                          
                                  const { selectionStart, selectionEnd } = sf.ui.proTools.selectionGetInSamples();
                                  const selectedTracks = sf.ui.proTools.selectedTrackNames;
                          
                          
                                  selectedTracks.forEach(track => {
                                      sf.ui.proTools.trackSelectByName({
                                          names: [track],
                                          deselectOthers: true
                                      }, `error selecting track: ${track}`);
                          
                                      sf.ui.proTools.selectionSetInSamples({ selectionStart, selectionEnd });
                                      sf.keyboard.press({ keys: 'left' }, `error in keyboard.press: left`); //update pro tools menu ui
                                      
                                      const clipName = getCurrentClipName();
                                      renameTrackFromClipName(clipName);
                                  })
                          
                          
                                  sf.ui.proTools.trackSelectByName({ names: selectedTracks });
                                  sf.ui.proTools.selectionSetInSamples({ selectionStart, selectionEnd });
                              
                              } catch (err) {
                                  throw `error in main(): ${err}`
                              }
                              alert('Done');
                          }
                          
                          main();
                          
                          
                          1. MMichael Bouska @Michael_Bouska
                              2021-02-28 22:15:07.843Z

                              hot damn! This works like a charm!! THANK YOU!

                              1. Dustin Harris @Dustin_Harris
                                  2021-02-28 22:33:43.225Z

                                  My pleasure! Useful one to make!

                                • In reply toDustin_Harris:

                                  That's awesome! Love the error handling and clever use of destructuring to get the selection values!

                                  1. Dustin Harris @Dustin_Harris
                                      2021-03-01 03:25:54.854Z

                                      It was a game changer to realize I could shorten {name: name,} to just {name,} :)

                                • Henrik Skram @Henrik_Skram
                                    2022-06-08 09:43:06.357Z

                                    Hi, can´t get this one to work, I get this error:
                                    08.06.2022 11:41:34.30 [Backend]: JavaScript error with InnerException: null
                                    !! Command Error: Name track from clip [user:ckzbejwdr0001wz10j2ba2kxx:cl45e7awh0000qu1089bq93ur]:
                                    TypeError: Cannot read property 'trackName' of undefined
                                    (Name track from clip line 84)

                                    Any pointers would be greatly appreciated!

                                    1. If you're running the latest version of PT (2022.5 at this time) be sure you are running the latest version of SoundFlow (5.1.5). You may have to install it manually from here:

                                      https://my.soundflow.org/install

                                      1. If this doesn't work let us know here.

                                    2. A
                                      Alexis Cuadrado @Alexis_Cuadrado
                                        2023-01-08 15:48:28.353Z

                                        Hi there,
                                        Spanking brand new to SF, so I'm probably doing something wrong!
                                        Tried to run this script (created a package, created a script, assigned a key command), and it didn't work.
                                        Getting this error message:

                                        08.01.2023 10:47:15.22 [Backend]: !! Command Error: Rename Track from Clip Name [user:clcnjncgs0000jy10v0l5dj76:clcnjo2gi0001jy10fzqp59jg]:
                                        error in main(): Error: KeyboardPressAction
                                        (Rename Track from Clip Name line 39)

                                        Thank you so much in advance for any help

                                        1. Same here, don't know why...

                                          1. @Dustin_Harris can you help us out? This is way beyond my skills :)

                                            1. Dustin Harris @Dustin_Harris
                                                2023-06-23 13:42:38.916Z

                                                Oh wow! Looks like the sf.keyboard.press has become case-sensitive!

                                                try replacing sf.keyboard.press({ keys: 'Left' }); //update pro tools menu ui
                                                with
                                                sf.keyboard.press({ keys: 'left' }); //update pro tools menu ui

                                                I'm going to update the whole script. brb.

                                                1. Dustin Harris @Dustin_Harris
                                                    2023-06-23 13:53:22.784Z

                                                    I've updated the script in the post here:

                                                    1. Same error here as before :)

                                                      1. Error report:

                                                        23.06.2023 15:56:31.20 [Backend]: #StreamDeck: KeyDown (3,4) -> Rename From Region

                                                        23.06.2023 15:56:31.20 [Backend]: >> Command: Rename From Region [user:default:clj8j2qdf0001bk10qzr3spiu]

                                                        23.06.2023 15:56:31.20 [Backend]: Checking for running apps with bundle 'com.avid.ProTools'

                                                        23.06.2023 15:56:31.20 [Backend]: NSArray.ArrayFromHandle count = 1

                                                        23.06.2023 15:56:31.28 [Backend]: Mouse current pos is: (1260,819091796875, 238,03866577148438)
                                                        Clicking with mouse here: (12, 62)

                                                        23.06.2023 15:56:31.29 [Backend]: Moving mouse back to: (1260,819091796875, 238,03866577148438)

                                                        23.06.2023 15:56:31.29 [Backend]: Position is now: (1260,819091796875, 238,03866577148438)

                                                        23.06.2023 15:56:31.75 [Backend]: Succesfully set selection to: MainCounter: Sel Start: 0 Sel End: 7931279 Sel Length:

                                                        23.06.2023 15:56:31.75 [Backend]: Logging error in action (01) KeyboardPressAction: Key 'Left' wasn't recognized.

                                                        23.06.2023 15:56:31.75 [Backend]: JavaScript error with InnerException: null
                                                        !! Command Error: Rename From Region [user:default:clj8j2qdf0001bk10qzr3spiu]:
                                                        error in main(): Error: KeyboardPressAction
                                                        (Rename From Region line 39)

                                                        1. Dustin Harris @Dustin_Harris
                                                            2023-06-23 14:01:58.949Z

                                                            looks like there is still an uppercase 'L' in 'left'?

                                                            1. I have it working now, I didn't copy paste it correctly. Sorry! This is awesome thanx!!!!!

                                                              1. Dustin Harris @Dustin_Harris
                                                                  2023-06-23 14:08:33.451Z

                                                                  Awesome! Glad it's working now!

                                                          • In reply toDustin_Harris:

                                                            I have it working now, I didn't copy paste it correctly. Sorry! This is awesome thanx!!!!!