The following macro duplicates the track and renames it numerically. The way it’s written takes a long time to execute when doing several tracks. Is there a way to rewrite it so that it first duplicates the tracks (which is fast in ProTools) and then renames them? Maybe this would be faster?
Also, can we build in an if/then so that if I don’t happen to have a number after the first track, it would add a number to the track we are duplicating and then continue. Right now if my source track to duplicate is named “DX_M", then the macro fails. It has to be named “DX_M1" for the macro to work.
Let me know if this is doable. Thanks!
—-__________
//This script duplicates a selected track a given amount of times (defaulting to “1” duplicate) without the .dupXX suffix
//Note: This should be assigned to a keyboard shortcut or Stream Deck button.
function getAndIncrementLastNumber(str) {
return str.replace(/\d+$/, function (s) {
return ++s;
});
}
function duplicateSelectedTrack() {
sf.ui.proTools.trackDuplicateSelected({
duplicateActivePlaylist: false,
duplicateAlternatePlaylists: false,
duplicateAutomation: false,
});
}
function renameTrack() {
sf.ui.proTools.selectedTrack.trackOpenRenameDialog();
}
function incrementTrackName() {
//Get the current track name
var sourceTrackName = sf.ui.proTools.selectedTrackNames[0];
//Variable for new track name
var newTrackName = getAndIncrementLastNumber(sourceTrackName);
//Duplicate selected track
duplicateSelectedTrack();
//Rename track
renameTrack();
//Add the track name with incemented number
sf.ui.proTools.windows.first.textFields.first.elementSetTextFieldWithAreaValue({ value: newTrackName });
//Click OK in Track Rename window
sf.ui.proTools.windows.first.buttons.whoseTitle.is('OK').first.elementClick();
}
function main() {
//Make sure Pro Tools Main Window is active
sf.ui.proTools.appActivateMainWindow();
var defaultValue = 1;
var numberOfDuplicates = prompt("How many duplicates do you want?", 1);
if (numberOfDuplicates == "null" || numberOfDuplicates == null) {
throw 0;
}
//Loop for entered number of duplicates
for (var i = 0; i < Number(numberOfDuplicates); i++) {
incrementTrackName();
}
}
main();
- Christian Scheuer @chrscheuer2020-10-21 23:08:44.408Z
This is the method I use - perhaps it already solves your need:
- JJonathan Grossman @Jonathan_Grossman
holy C^%$!! That is a fast macro. amazing. thank you Christian. how would I modify it to add a the number "1" to the end of track title if it isn't already there. And of course if it is already there, then just continue with the macro
Christian Scheuer @chrscheuer2020-10-22 00:05:32.704Z
:)
Unfortunately in that script, the renaming logic is hidden in some old, internal SoundFlow code that isn't written in Javascript, so it's not easy to change the logic - it would have to be written from scratch.
But from what you're saying, if you can keep that logic, and the remaining issue is just to rename the current track if it doesn't end with a number, you can do that like this:
This checks if the current track name ends with a number, if it doesn't, it adds " 1" (space and a 1) to the track name:
if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) { sf.ui.proTools.selectedTrack.trackRename({ renameFunction: n => n + ' 1', }); }
- JJonathan Grossman @Jonathan_Grossman
Well that's just superb. Works great.
btw - I had to add some script at the beginning of the original to set the track height to small bc if the source track was at the bottom of the session in a medium size and I tried to make 10 duplicates, it would go off the bottom of the screen and the macro would fail. The complete script looks like this now.
var size = 'small'; var f = sf.ui.proTools.selectedTrack.frame; var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({ relativePosition: { x: f.w - 10, y: 5 }, isOption: true, isShift: true, }).popupMenu; popupMenu.menuClickPopupMenu({ menuPath: [size] }); if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) { sf.ui.proTools.selectedTrack.trackRename({ renameFunction: n => n + '1', }); } var numberOfDups = Number(prompt('How many duplicates?', '1')); var originalTrackName = sf.ui.proTools.selectedTrackNames[0]; sf.ui.proTools.trackDuplicateSelected({ duplicateActivePlaylist: false, duplicateAlternatePlaylists: false, duplicateAutomation: false, duplicateGroupAssignments: true, duplicateInserts: true, duplicateSends: true, insertAfterLastSelectedTrack: true, numberOfDuplicates: numberOfDups }); sf.ui.proTools.trackSelectByName({ names: [originalTrackName], deselectOthers: false }); sf.ui.proTools.selectedTrack.trackBulkRenameNumerical();
Kitch Membery @Kitch2020-10-22 00:39:01.639Z
Here is a video I put together on how to Quote Code in the SoundFlow Forum. It will make it easier for us to read your scripts :-)
- JJonathan Grossman @Jonathan_Grossman
so it;ll look like this in the future
var size = 'small'; var f = sf.ui.proTools.selectedTrack.frame; var popupMenu = sf.ui.proTools.selectedTrack.popupMenuOpenFromElement({ relativePosition: { x: f.w - 10, y: 5 }, isOption: true, isShift: true, }).popupMenu; popupMenu.menuClickPopupMenu({ menuPath: [size] }); if (!sf.ui.proTools.selectedTrack.normalizedTrackName.match(/\d+$/)) { sf.ui.proTools.selectedTrack.trackRename({ renameFunction: n => n + '1', }); } var numberOfDups = Number(prompt('How many duplicates?', '1')); var originalTrackName = sf.ui.proTools.selectedTrackNames[0]; sf.ui.proTools.trackDuplicateSelected({ duplicateActivePlaylist: false, duplicateAlternatePlaylists: false, duplicateAutomation: false, duplicateGroupAssignments: true, duplicateInserts: true, duplicateSends: true, insertAfterLastSelectedTrack: true, numberOfDuplicates: numberOfDups }); sf.ui.proTools.trackSelectByName({ names: [originalTrackName], deselectOthers: false }); sf.ui.proTools.selectedTrack.trackBulkRenameNumerical();
Christian Scheuer @chrscheuer2020-10-22 11:14:25.961Z
Great! Thanks for sharing :)
- CIn reply toJonathan_Grossman⬆:Christian Best @Christian_Best
Thanks for got this,very handy.
Its working on single tracks,,is there a way to make this work on groups of tracks?
for example if i have a group like thisEgtr Con 1
Egtr Ribb 1
Egtr DI 1could i then highlight all 3 channels and run a command to make them labelled
Egtr Con 2
Egtr Ribb 2
Egtr DI 2?
Thanks in advance guys
Christian