No internet connection
  1. Home
  2. How to

Auto-naming playlists when duplicating

Originally asked in this thread by @Andrew_Scheps

Is there an easy way to apply this to a playlist name? I'd like to be able to duplicate a playlist, incrementing the (original) last number in the name (which is the last digit). So I also need to get rid of the three characters added when you invoke Duplicate Playlist.

Solved in post #3, click to view
  • 15 replies

There are 15 replies. Estimated reading time: 12 minutes

  1. Kitch Membery @Kitch2020-02-16 00:46:29.415Z2020-02-16 00:58:42.763Z

    Hi @Andrew_Scheps,

    Massive fan of your work mate. I'm sure @chrscheuer will chime in with some improvements but here is a script I wrote for this purpose. It works for one track only but could be changed to do multiple channels.

    Hope it helps.
    Kitch

    //Make sure Pro Tools Edit Window is active
    sf.ui.proTools.appActivateMainWindow();
    
    //Get the current track/playlist name
    var oldPlaylistName = sf.ui.proTools.selectedTrackNames[0];
    
    //Duplicate selected track playlist
    sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
        menuPath: ["Duplicate..."],
    });
    
    //Wait for Duplicate Playlist window to appear
    sf.ui.proTools.confirmationDialog.elementWaitFor({waitType: "Appear",});
    
    //Click OK in Duplicate Playlist window
    sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is('OK').first.elementClick();
    
    //Wait for Duplicate Playlist window to disappear
    sf.ui.proTools.confirmationDialog.elementWaitFor({waitType: "Disappear",});
    
    //Get and Increment Last Number
    function getAndIncrementLastNumber(str) {
        return str.replace(/\d+$/, function (s) {
            return ++s;
        });
    }
    
    //Variable for new clip name
    var newPlaylistName = getAndIncrementLastNumber(oldPlaylistName);
    
    //Rename Track with Old Name + Incrimented value
    sf.ui.proTools.selectedTrack.trackRename({
        newName: newPlaylistName,
    });
    

    Here is a video of it in action;

    1. OOrlando Ferrer @Orlando_Ferrer
        2020-10-24 16:06:00.655Z

        For the benefit of the members here:

        For this script to work, you have to be sure to disable the preference to suppress new playlist dialog under Pro Tools>Preferences>Editing>Supress Name Dialog When Creating New Playlist.

      • In reply tochrscheuer:
        Kitch Membery @Kitch2020-02-16 08:44:13.555Z

        FYI... The following script does it in one less step. Hope that helps.
        Rock on
        Kitch

        //Make sure Pro Tools Edit Window is active
        sf.ui.proTools.appActivateMainWindow();
        
        //Get the current track/playlist name
        var oldPlaylistName = sf.ui.proTools.selectedTrackNames[0];
        
        //Get and Increment Last Number
        function getAndIncrementLastNumber(str) {
            return str.replace(/\d+$/, function (s) {
                return ++s;
            });
        }
        
        //Variable for new clip name
        var newPlaylistName = getAndIncrementLastNumber(oldPlaylistName);
        
        //Duplicate selected track playlist
        sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
            menuPath: ["Duplicate..."],
        });
        
        //Wait for Duplicate Playlist window to appear
        sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: "Appear", });
        
        sf.ui.proTools.confirmationDialog.textFields.first.elementSetTextFieldWithAreaValue({ value: newPlaylistName });
        
        //Click OK in Duplicate Playlist window
        sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is('OK').first.elementClick();
        
        //Wait for Duplicate Playlist window to disappear
        sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: "Disappear", });
        
        ReplySolution
        1. Andrew Scheps @Andrew_Scheps
            2020-02-16 10:20:17.494Z

            Brilliant, thanks! And the second way I have the track name in a variable that I can use later in the script.

            1. Kitch Membery @Kitch2020-02-16 10:27:57.492Z

              You are totally welcome mate. :-)

          • A
            In reply tochrscheuer:
            Andrew Downes @Andrew_Downes
              2020-04-22 00:44:30.950Z

              How would I alter this script so it doesn't have to have a number to start with?
              e.g Kick becomes Kick 1 and the new Playlist becomes Kick 2 and so on.
              Thanks

              1. GGary Keane @Gary_Keane
                  2023-01-23 16:28:58.958Z

                  Any joy with this? Have the same issue with getting an error when no number is already in the track name. Any ideas @Kitch @chrscheuer Thanks alot in advance

                  1. Kitch Membery @Kitch2023-01-23 20:04:30.249Z

                    I'll take a look :-)

                    1. In reply toGary_Keane:
                      Kitch Membery @Kitch2023-01-23 20:19:31.286Z

                      Hi @Gary_Keane,

                      This should do the trick :-)

                      //NOTE: For this script to work, disable the preference to suppress new playlist dialog under
                      //Pro Tools > Preferences > Editing > Supress Name Dialog When Creating New Playlist
                      
                      function incrementPlaylistNumber(str) {
                          var numberRegex = /\d+$/;
                          var match = str.match(numberRegex);
                          if (match) {
                              var number = parseInt(match[0]) + 1;
                              return str.replace(numberRegex, number);
                          } else {
                              return str + " 2";
                          }
                      }
                      
                      function duplicatePlaylistIncrement() {
                          //Activate Pro Tools main window
                          sf.ui.proTools.appActivateMainWindow();
                      
                          //Get the current track/playlist name
                          var oldPlaylistName = sf.ui.proTools.selectedTrackNames[0];
                      
                          //Create new playlist name
                          var newPlaylistName = incrementPlaylistNumber(oldPlaylistName);
                      
                          //Duplicate selected track playlist
                          sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
                              menuPath: ["Duplicate..."],
                          });
                      
                          const dlg = sf.ui.proTools.confirmationDialog;
                      
                          //Wait for Duplicate Playlist window to appear
                          dlg.elementWaitFor({ waitType: "Appear", });
                      
                          //Add new playlist name
                          dlg.textFields.first.elementSetTextFieldWithAreaValue({
                              value: newPlaylistName
                          });
                      
                          //Click OK in Duplicate Playlist window
                          dlg.buttons.whoseTitle.is('OK').first.elementClick();
                      
                          //Wait for Duplicate Playlist window to disappear
                          dlg.elementWaitFor({ waitType: "Disappear", });
                      }
                      
                      duplicatePlaylistIncrement();
                      

                      Rock on!

                      1. GGary Keane @Gary_Keane
                          2023-01-24 12:08:09.485Z

                          You the man Kitch!

                          1. In reply toKitch:
                            GGary Keane @Gary_Keane
                              2023-01-24 12:11:25.313Z

                              Sorry @Kitch , is there a way that, after the playlist is duplicated, it automatically goes back to the playlist I just duplicated from? I duplicate playlists to keep as safety copies before I start AudioSuiting them hence me wanting to jump right back to the playlist I duplicated from :)

                              1. Kitch Membery @Kitch2023-01-24 19:23:25.244Z

                                This is untested, but it should do the job of switching back to the old playlist.

                                //NOTE: For this script to work, disable the preference to suppress new playlist dialog under
                                //Pro Tools > Preferences > Editing > Supress Name Dialog When Creating New Playlist
                                
                                function incrementPlaylistNumber(str) {
                                    var numberRegex = /\d+$/;
                                    var match = str.match(numberRegex);
                                    if (match) {
                                        var number = parseInt(match[0]) + 1;
                                        return str.replace(numberRegex, number);
                                    } else {
                                        return str + " 2";
                                    }
                                }
                                
                                function selectPlaylistByName({ name }) {
                                    sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
                                        menuSelector: items => items.filter(i => i.path[0].replace(/ \(\d+\)$/, '') === name)[0]
                                    });
                                }
                                
                                function duplicatePlaylistIncrement() {
                                    //Activate Pro Tools main window
                                    sf.ui.proTools.appActivateMainWindow();
                                
                                    //Get the current track/playlist name
                                    var oldPlaylistName = sf.ui.proTools.selectedTrackNames[0];
                                
                                    //Create new playlist name
                                    var newPlaylistName = incrementPlaylistNumber(oldPlaylistName);
                                
                                    //Duplicate selected track playlist
                                    sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
                                        menuPath: ["Duplicate..."],
                                    });
                                
                                    const dlg = sf.ui.proTools.confirmationDialog;
                                
                                    //Wait for Duplicate Playlist window to appear
                                    dlg.elementWaitFor({ waitType: "Appear", });
                                
                                    //Add new playlist name
                                    dlg.textFields.first.elementSetTextFieldWithAreaValue({
                                        value: newPlaylistName
                                    });
                                
                                    //Click OK in Duplicate Playlist window
                                    dlg.buttons.whoseTitle.is('OK').first.elementClick();
                                
                                    //Wait for Duplicate Playlist window to disappear
                                    dlg.elementWaitFor({ waitType: "Disappear", });
                                
                                    //Select Original playlist
                                    selectPlaylistByName({ name: oldPlaylistName });
                                }
                                
                                duplicatePlaylistIncrement();
                                

                                This may however not work as a reusable workflow though, as it will only increment the playlist name the first time you run it, the second time it will then try to duplicate the playlist with the same name as the previous backup. It will then throw a dialog saying that there is already a playlist with this name.

                                1. GGary Keane @Gary_Keane
                                    2023-01-25 14:19:33.481Z

                                    Perfect Kitch, thank you!

                          2. K
                            In reply tochrscheuer:
                            Kenny Cheng @Kenny_Cheng
                              2020-08-06 05:52:39.719Z

                              Hi Chris,
                              I tried to modify this script to work for renaming track incrementally.
                              What I did was delete the duplicate playlist part and seems it works.

                              This altered script seems working for single track.
                              But what if I want to rename multiple selected tracks?

                              Thank you

                              1. Hi Kenny,

                                Please start a new thread on this and describe in the question exactly what you'd like the script to do with some examples of what kind of renaming you'd like for before/after renaming of the track names.