Batch Track and Clip Rename Advice
Hi All! I'm looking for two very basic scripts. One would be a Find/Replace on track name, the other would be a Suffix on the clip name. Sadly I'm not great at scripting so any help would be hugely appreciated.
Script 1: Track Rename to Find MIX01 and replace with MIX02, I'd then duplicate this so I could simply hit a corresponding button to up the mix version before printing stems. I could certainly edit the code to change the number if I had the basic
Script 2: Add "_BLANK" to the end of a clip name automatically using batch clip rename,
Any and all help greatly appreciated!
- Raphael Sepulveda @raphaelsepulveda2022-08-25 00:04:02.085Z
Hey @Scott_Smith,
I can help you with that first request!
The script below will check if the selected track has the text "MIX01"—or whichever number (02, 03, etc...). If it does, it will rename that track and increment the number automatically. That way you don't have to have multiple scripts for each version number.
/** * Searches for "MIX##" in the selected track name and, if found, * renames it with the ## incremented by 1. */ function main() { const regEx = /(MIX)(\d\d)/; // For example, MIX01 const trackName = sf.ui.proTools.selectedTrack.normalizedTrackName; const trackNameMatch = trackName.match(regEx); if (!trackNameMatch) throw `Selected track doesn't contain "MIX##" in its name.`; const [_, mix, versionNum] = trackNameMatch; // Resulting array = [MIX01, MIX, 01] let newVersionNum = String(Number(versionNum) + 1); // Increments. "2" if (newVersionNum.length < 2) { newVersionNum = "0" + newVersionNum; // "02" } const newName = trackName.replace(regEx, "$1" + newVersionNum); // MIX02 sf.ui.proTools.selectedTrack.trackRename({ newName }); } main();
Hopefully, someone else can chime in for your second request, although I'd recommend asking in a separate post since bundled requests usually don't get as many replies.
Let me know how it goes!
- SScott Smith @Scott_Smith
Thanks so much! I made an edit, just using my initial instead of MIX. In either case when I run the command it says" Could not open track rename dialog, Line 23'
Thoughts? Heres the edited script:
/**-
Searches for "SMS##" in the selected track name and, if found,
-
renames it with the ## incremented by 1.
*/
function main() {
const regEx = /(SMS)(\d\d)/; // For example, MIX01const trackName = sf.ui.proTools.selectedTrack.normalizedTrackName;
const trackNameMatch = trackName.match(regEx);if (!trackNameMatch) throw
Selected track doesn't contain "SMS##" in its name.
;const [_, mix, versionNum] = trackNameMatch; // Resulting array = [SMS01, SMS, 01]
let newVersionNum = String(Number(versionNum) + 1); // Increments. "2"
if (newVersionNum.length < 2) {
newVersionNum = "0" + newVersionNum; // "02"
}const newName = trackName.replace(regEx, "$1" + newVersionNum); // MIX02
sf.ui.proTools.selectedTrack.trackRename({
newName
});
}
main();
Raphael Sepulveda @raphaelsepulveda2022-08-25 18:55:01.647Z
The
trackRename()
function needs to perform an action on the title of the track in order to open the Rename window. Try the following troubleshooting steps:- Check that you're performing the action on the Edit window—since this only works on the Edit window currently.
- Check that there are no floating windows above the track name.
- Finally, make sure that the track is within view—if it's scrolled out of sight, then SoundFlow won't be able to click on it.
Oh, and for future reference, here's a video on how to quote code in the forum!
- SScott Smith @Scott_Smith
Thanks Raphael! When I do this, it will open the track rename window for my first print track but then it just stops. If I hit enter it will toggle through each track highlighted, but its not changing the name at all. I use pretty verbose track names as I work in film. For instance:
MMC 3m37bv1.5 cPC2v5 SMS01_03_Brass_StemThanks so much for all your help
Raphael Sepulveda @raphaelsepulveda2022-08-25 21:20:51.113Z
Ah, I wrote that script with a single selected track in mind. I just tested it with multiple tracks selected and can see where it's going wrong.
In my testing, it did change the name of the first track (using the long track name you provided), but stalls after clicking ok.
This should fix that:
function renameFunction(trackName) { const regEx = /(SMS)(\d\d)/; // For example, SMS01 const trackNameMatch = trackName.match(regEx); if (!trackNameMatch) return trackName; const [_, prefix, versionNum] = trackNameMatch; // Resulting array = [SMS01, SMS, 01] let newVersionNum = String(Number(versionNum) + 1); // Increments. "2" if (newVersionNum.length < 2) { newVersionNum = "0" + newVersionNum; // "02" } const newName = trackName.replace(regEx, "$1" + newVersionNum); // SMS02 return newName; } /** @param {{ renameFunction: (trackName: string) => string }} arg */ function trackBulkRename({ renameFunction }) { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.mainWindow.invalidate(); const selectedTrackNames = sf.ui.proTools.selectedTrackNames; sf.ui.proTools.selectedTrack.trackSelect(); sf.ui.proTools.selectedTrack.trackScrollToView(); sf.ui.proTools.trackSelectByName({ names: selectedTrackNames }); sf.ui.proTools.selectedTrack.titleButton.popupMenuSelect({ isRightClick: true, menuPath: ["Rename..."] }); selectedTrackNames.forEach(trackName => { const renameWin = sf.ui.proTools.windows.whoseTitle.is(trackName).first; renameWin.elementWaitFor(); renameWin.textFields.first.elementSetTextFieldWithAreaValue({ value: renameFunction(renameWin.textFields.first.value.value) }); renameWin.buttons.whoseTitle.is("OK").first.elementClick(); renameWin.elementWaitFor({ waitType: "Disappear" }); }); } trackBulkRename({ renameFunction });
-