No internet connection
  1. Home
  2. How to

Copy track name to clip name

By samuel henriques @samuel_henriques
    2020-08-30 18:29:13.011Z

    Hello,
    I managed to do this script to copy the track name to the clip name.
    This is for my stem tracks, each track only has one clip.

    sf.ui.proTools.selectedTrack.trackOpenRenameDialog();
    sf.wait({
        intervalMs: 10,
    });
    sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Copy'] });
    sf.keyboard.press({
        keys: "return",
    });
    sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
    sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.whoseTitle.is('Name').first.radioButtons.whoseTitle.is('name clip only').first.checkboxSet({
        targetValue: "Enable",
    });
    sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] });
    sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick()
    
    

    Could you help me change this so it would to this on every selected track?

    Thank you so much

    Solved in post #3, click to view
    • 12 replies
    1. samuel henriques @samuel_henriques
        2020-08-30 22:15:38.740Z2020-08-30 22:23:07.302Z

        right...
        once again I couldn't let go and spend the past hours trying to figure this out...
        I don't know how to code so this is all done with the help of the incredible search function of the forum.

        This script will change the clip name to be the same as the track name, on all selected tracks and in the end open the batch rename to I can add a version in the end.

        This is meant rename stem files, assuming there is only one file pre track. It will work if there's more than one clip on the track.
        for that, I guess consolidate clips before will make it work

        this is a newbie's code, so if you could find anything to be improved please let me know.

        
        
        sf.ui.proTools.appActivateMainWindow();
        
        function rename() {
        sf.ui.proTools.selectedTrack.trackOpenRenameDialog();
        sf.wait({
            intervalMs: 5,
        });
        sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Copy'] });
        sf.keyboard.press({
            keys: "return",
        });
        sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
        sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.whoseTitle.is('Name').first.radioButtons.whoseTitle.is('name clip only').first.checkboxSet({
            targetValue: "Enable",
        });
        sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] });
        sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick()
        }
        
        function main() {
            //Invalidate Pro Tools main window.
            sf.ui.proTools.mainWindow.invalidate();
        
            //Get selected tracks
            const originalTracks = sf.ui.proTools.selectedTrackNames;
        
            //Scroll first selected track to into view
            sf.ui.proTools.selectedTrack.trackScrollToView();
        
        
        
            //Do for each track.
            sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
        
                //Select track
                track.trackSelect();
        
                rename();
        
                //Scroll track into View
                track.trackScrollToView();
        
                //Fetch track title
                let selectedTrackTitle = track.title.invalidate().value;
        
        
        
            });
        
            //Restore previously selected tracks
            sf.ui.proTools.trackSelectByName({ names: originalTracks });
        }
        
        main();
        
        sf.keyboard.press({
            keys: "ctrl+shift+r",
        });
        sf.ui.proTools.windows.whoseTitle.is('Batch Clip Rename').first.buttons.whoseDescription.is('').allItems[4].elementClick();
        
        

        Thank you so much

        1. Kitch Membery @Kitch2020-08-31 00:29:05.930Z2020-08-31 00:47:38.000Z

          Try this mate!

          function renameClip() {
              //Get selected track Name
              let trackName = sf.ui.proTools.selectedTrackNames[0];
          
              //Open Rename window
              sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] });
          
              //Reference for Rename Window
              const win = sf.ui.proTools.windows.whoseTitle.is('Name');
          
              //Wait for rename Window
              win.first.elementWaitFor();
          
              //Set the clip name to Track name
              win.first.groups.first.textFields.first.elementSetTextFieldWithAreaValue({
                  value: trackName,
              });
          
              //Click OK
              win.first.buttons.whoseTitle.is('OK').first.elementClick()
          }
          
          function main() {
              //Invalidate Pro Tools main window.
              sf.ui.proTools.mainWindow.invalidate();
          
              //Get selected tracks
              const originalTracks = sf.ui.proTools.selectedTrackNames;
          
              //Scroll first selected track to into view
              sf.ui.proTools.selectedTrack.trackScrollToView();
          
              //Do for each track.
              sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => {
          
                  //Select track
                  track.trackSelect();
                  
                  //Scroll track into View
                  track.trackScrollToView();
          
                  //Run Rename Clip function
                  renameClip();
              });
          
              //Restore previously selected tracks
              sf.ui.proTools.trackSelectByName({ names: originalTracks });
          
          //Open Batch Clip Rename
          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();
          }
          
          main();
          

          Great work figuring it out!

          Here are a few changes. I've removed some unnecessary mouse click and keyboard automation to make the script more robust and snappy.

          More could be done to make it more robust and more error handeling could be added but this should do the trick.

          Rock on!

          Reply3 LikesSolution
          1. samuel henriques @samuel_henriques
              2020-08-31 09:05:56.257Z

              Hey Kitch,
              Awesome, thats way better.

              Thank you so much!!!!

              1. Kitch Membery @Kitch2020-08-31 09:10:04.362Z

                A pleasure as always mate :-)

          2. M
            Matt Friedman @Matt_Friedman
              2021-09-09 15:50:57.279Z

              I would love to see the opposite of this. Copy clip name to track name, for currently selected clips/tracks.

              1. TTom Davis @Tom_Davis
                  2024-03-12 18:45:30.097Z

                  yes me too! AND enter the copied clip name into the comments box as well that track name. Anyone?

                  1. In reply toMatt_Friedman:
                    LLukas paschke @Lukas_paschke
                      2024-10-07 15:20:08.554Z

                      anyone made this?

                      1. samuel henriques @samuel_henriques
                          2024-10-09 11:56:47.511Z

                          Helo,
                          Try this and let me know. If it's not working well, I might have another one

                      2. J
                        Jack Byrne @Jack_Byrne
                          2021-10-09 20:07:30.345Z

                          Hey! Newbie to SF here, tried running this script and get an error from the updated script that @Kitch posted, stops at line 50 (the batch rename section). Mostly needed the renaming clips by tracks bit, but I thought I'd let folks know as I've not a clue how to troubleshoot script yet!

                          1. samuel henriques @samuel_henriques
                              2021-10-10 11:25:50.101Z

                              Hello Jack,
                              I don't remember exactly where I went from here with this script. It seams that after renaming the clips I wanted do do more with the batch rename.

                              If you remove these lines, it should rename the clips with track name. But this only works if you only have one clip on each track.

                              Remove this:

                              //Open Batch Clip Rename
                              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();
                              
                            • P
                              Pete Watson @Pete_Watson
                                2022-02-20 13:07:35.030Z

                                Great work on this - very helpful thanks!

                                I think the error on line 50 will happen if the clip list window is hidden (which makes sense as then batch rename isn't available).

                                I'm new to this but will try and put in a check for that and repost if I succeed. Also it's worth disabling groups, and checking to make sure "link edit and track selection" is active too as I for one have that disabled... back soon :)

                                1. samuel henriques @samuel_henriques
                                    2022-02-22 16:07:13.034Z

                                    Hello Pete,
                                    You are correct.

                                    You can add:

                                    sf.ui.proTools.menuClick({ menuPath: ["View", "Other Displays", "Clip List"], targetValue: "Enable" })
                                    

                                    before line 49 //Open Batch Clip Rename and it should be fine.