Hello everyone,
I’m working on a script to automate the creation of seperate Clipgroups on all audio tracks that contain clips.
Here’s the process I’m aiming for:
- Manually select the first track over the length of my project.
- Run the script.
So far, my script can create a Clipgroup on one track and move to the next track, skipping empty tracks and folder headers. I found inspiration for this in other forum posts.
However, I'm facing some challenges and would appreciate any advice or improvements:
It would be awesome if the script would loop itself until it reaches the last track in my session at the bottom.
Here's the code I've developed so far:
//detection of folder track
const doesTrackSelectionContainAFolderTrack = sf.ui.proTools.selectedTrackHeaders.some(trackHeader => {
return trackHeader.title.value.endsWith("Folder Track ");
});
if (doesTrackSelectionContainAFolderTrack) {
// Running this if selection includes a folder track
// Step Down one Track
sf.keyboard.press({
keys: "semicolon",
});
} else {
sf.ui.proTools.appActivateMainWindow();
//Check if clips are within the selection
const audioExists = sf.ui.proTools.getMenuItem('Edit', 'Trim Clip', 'To Selection').isEnabled;
if(audioExists){
//Group Clips
sf.keyboard.press({
keys: "cmd+alt+g",
});
} else {
//step down, because the track was empty
}
// Step Down one Track
sf.keyboard.press({
keys: "semicolon",
});
//short pause
sf.wait({
intervalMs: 50,
});
}
Thanks in advance for any guidance!
- OOwen Granich-Young @Owen_Granich_Young
Here's an old do for each track template, see if it helps? You'd have to change your approach a little since you have it moving from track to track already on your script, so instead think of simplifying the action to 'if there are cilps -> Do the funciton) if not move on. So I think you can broom your step down one track etc. at line 27
I'm pretty sure if you search the forum too there's a way to have it only select audio tracks (after you've selected everything) at the beginning of the script before running the 'do for each track' so that you can skip folders auxes etc as well.
function action() { /// Code to repeat on every selected track goes here. } //Get selected tracks const originalTracks = sf.ui.proTools.selectedTrackNames; //Do for each track. sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => { //Select track track.trackSelect(); //Scroll track into View track.trackScrollToView(); action() }); //Restore previously selected tracks sf.ui.proTools.trackSelectByName({ names: originalTracks });
Happy coding!
- OOwen Granich-Young @Owen_Granich_Young
Reselect Visible Audio Tracks from current track selection #post-2 Found it... so a quick code (untested so no garuntee :P)
function grpIfAudio() { //Check if clips are within the selection const audioExists = sf.ui.proTools.getMenuItem('Edit', 'Trim Clip', 'To Selection').isEnabled; if (audioExists) { sf.ui.proTools.menuClick({ menuPath: ["Clip", "Group"], }); }; } function main() { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.invalidate(); // Get all selected track headers let allSelectedTrackHeaders = sf.ui.proTools.invalidate().trackGetSelectedTracks().trackHeaders; //Filter to get only visible audio tracks let allVisibleSelectedAudioTrackNames = allSelectedTrackHeaders.filter(t => t != null && t.title.value.endsWith("- Audio Track ")).map(t => t.normalizedTrackName); //Select only previously selected visible audio tracks sf.ui.proTools.trackSelectByName({ names: allVisibleSelectedAudioTrackNames, deselectOthers: true }); //Do for each selected track. sf.ui.proTools.selectedTracks.trackHeaders.slice().map(track => { //Select track track.trackSelect(); //Scroll track into View track.trackScrollToView(); grpIfAudio() }); } main();
AlexanderW @AlexanderW
Hey Owen,
Awesome. This looks much more elegant than what I've come up with so far. I secretly hoped for something like this. I will try that asap.Best, Alex
- OOwen Granich-Young @Owen_Granich_Young
haha, no promises, I didn't test at all, but you seem like you can trouble shoot it from there. FYI You'll see i swapped the
if(audioExists){ //Group Clips sf.keyboard.press({ keys: "cmd+alt+g", }); //TO if (audioExists) { sf.ui.proTools.menuClick({ menuPath: ["Clip", "Group"], });
Whenever possible use menuclicks instead of key commands because that way SF can know it's completed the task, it can't detect keyboard presses in the same way.
good luck!
OwenAlexanderW @AlexanderW
The beauty of smart code!
- In reply toOwen_Granich_Young⬆:
AlexanderW @AlexanderW
That works fabulously! Absolutely fantastic.
Only if a huge number of tracks are selected it seems to get a bit messy or might be caught in a loop. But that's no big deal. I could do it in two steps.
You saved my week!- OOwen Granich-Young @Owen_Granich_Young
I could see you needing to put some waits between the track select and then do to all tracks maybe if it gets really big? SDK stuff doesn't always know what UI stuff is doing and vice versa. I bet if you put like a 1 second wait at line 27 just to give the thing a breath before it jumps into it, it might fix that for you. Just a theory though.
AlexanderW @AlexanderW
I'll definitely try that. I also had some scripts before that needed a pause somewhere, but sometimes it is a bit tricky to find out at which line. Or even a command like: 'wait till xy is finished'