Incrementing a new or Duplicated Playlist with numbers
Inspired by the "Incrementing a Duplicated Track Name" thread, I am wodering if we can apply this to Playlists.
I have manged to bodge together a start by using some of Christian's code from the duplicate track rename post, and some from Andrew Scheps incrementing a playlist.
//Get the current track/playlist name
var oldPlaylistName = sf.ui.proTools.selectedTrackNames[0];
sf.ui.proTools.trackSelectByName({ names: [oldPlaylistName], deselectOthers: false });
sf.ui.proTools.selectedTrack.trackBulkRenameNumerical();
//Duplicate selected track playlist
sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is('Playlist selector').first.popupMenuSelect({
menuPath: ["New..."],
});
//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,
});
Where I am getting stuck, it seems, is after renaming the original playlist with a number, e.g "Guitar" goes to "Guitar 1". the new playlist is just called "Guitar" again. I'd like it to go to "Guitar 2" and so on.
None of this is a problem if a number already exsists in the trac name.
Thank you
- AAndrew Downes @Andrew_Downes
Hi All
I think I have managed to work it out for myself.
The following script will,
Add a number to the track name if there isn't one (1)
Make a Duplicate of the playlist
Increment that number to 2, and so on
If there is a number already, it will ignore the first bit.
If you remove the word "Duplicate" from line 14 and add "New", it will create a new playlist.I'm still working on getting it to work over multiple tracks.
sf.ui.proTools.appActivateMainWindow(); if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) { sf.ui.proTools.selectedTrack.trackRename({ renameFunction: n => n + ' 1', }); } //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, });
Thanks
Christian Scheuer @chrscheuer2020-10-23 16:40:54.137Z
Andrew - thanks so much for sharing this!
Christian Scheuer @chrscheuer2020-10-23 16:43:01.395Z
You can use this code to do a loop through all selected tracks:
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 } doForAllSelectedTracks(trackFunc);
- CIn reply toAndrew_Downes⬆:Christian Best @Christian_Best
I just tried this and it does relabel all selected tracks,,,,eg. Audio 1 to Audio 2
Is there a way of selecting the tracks and then Duplicating them then running this on the on the duplicates?this is the version with both scripts added together
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() { sf.ui.proTools.appActivateMainWindow(); if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) { sf.ui.proTools.selectedTrack.trackRename({ renameFunction: n => n + ' 1', }); } //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); ```