No internet connection
  1. Home
  2. How to

new playlist and name the track with the name of current playlist but with incremental numbering

By Jonathan Grossman @Jonathan_Grossman
    2022-02-10 23:16:30.996Z

    Can anyone help with this?

    Create a new playlist with the next numerical number as the suffix.

    For example, the current playlist is: BEST SONG EVER_MIX_V1 and I'd like a new playlist with the track now named BEST SONG EVER_MIX_V2

    Thank you!!!

    • 9 replies
    1. A
      Andrew Downes @Andrew_Downes
        2022-02-11 02:09:56.903Z

        Hi There
        This is what I use for that, or at least for Duplicating Playlists. I f you want a New Playlist replace Duplicate in the menu path wth New

        
        function doForAllSelectedTracks(action) {
            var originallySelectedTrackNames = sf.ui.proTools.selectedTrackNames;
        
            try {
                sf.ui.proTools.selectedTrackHeaders.forEach(track => {
                    track.trackSelect();
                    action(track);
                });
            }
            finally {
                sf.ui.proTools.trackSelectByName({ names: originallySelectedTrackNames });
            }
        }
        
        function trackFunc() {
        
            //Insert your code here
        sf.ui.proTools.appActivateMainWindow();
        
        if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) {
            sf.ui.proTools.selectedTrack.trackRename({
                renameFunction: n => n + ' t1',
            });
        }
        
        //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,
        });
        }
        
        doForAllSelectedTracks(trackFunc);
        1. TThomas Gloor @Thomas_Gloor
            2022-05-09 20:29:15.651Z

            Hey @Andrew_Downes

            Thank you for a great script! I was wondering if it would be possible to store the "increment" in a variable. Would you know?

            Basically, I'd like to get what the last number was, increment it by one and store the n+1 in a variable.

            Thanks!

            1. AAndrew Downes @Andrew_Downes
                2022-05-09 22:52:02.890Z

                Hi Thomas
                I imagine it would be possible, as it seems most things are in here, but its way outside my knowledge of scripting. There is bound to be someone in the forums who can help though.

                1. TThomas Gloor @Thomas_Gloor
                    2022-05-10 12:04:06.386Z

                    Thank you for your answer Andrew. I think i found a lead, will post if I find it!

              • J
                Jonathan Grossman @Jonathan_Grossman
                  2022-02-11 02:28:05.082Z

                  Thanks Andrew!

                  I'm getting an error on line 35. Any ideas?

                  10.02.2022 18:27:05.05 [Backend]: Logging error in action (01) WaitForElementAction: Element was not found or removed after waiting 2000 ms

                  10.02.2022 18:27:05.61 [Backend]: !! Command Error: NEW PLAYLIST V+ [user:ck99zpoez000h6e10rjx8vg5g:ckzhsbddb0000bx102ob52qc3]:
                  Element was not found or removed after waiting 2000 ms (NEW PLAYLIST V+: Line 35)

                  << Command: NEW PLAYLIST V+ [user:ck99zpoez000h6e10rjx8vg5g:ckzhsbddb0000bx102ob52qc3]

                  1. A
                    Andrew Downes @Andrew_Downes
                      2022-02-11 02:58:01.897Z

                      I am not getting any errors here.
                      The is a prefence in the editing tab in the tracks part 'Supress Name Dialog When Creating New Playlists' theis should be unticked.

                      1. Andrew - can we adjust this script so instead of "t1" it says "_V1" and goes incremental with that suffix?

                        1. AAndrew Downes @Andrew_Downes
                            2023-02-15 22:01:15.236Z

                            Of course you can!

                        2. J
                          Jonathan Grossman @Jonathan_Grossman
                            2022-02-11 04:03:43.137Z

                            yep - that fixed it. Thanks Andrew!