Title
Renaming Tracks with Comments
What do you expect to happen when you run the script/macro?
I want to be able to rename tracks with the comments field. Here's the scenario:
I'm working on a large session that has lots of weird naming happening probably due to importing a lot of audio files with weird names, but I might need to retain those weird track names in order to use import session data at a later date.
I have a script that will copy the track names to the Comments so that I can rename tracks in a way that makes sense. Now I'm looking to copy those names from the Comments back to the track name. I have a script where I can do this one track at a time, but I want to be able to select multiple tracks and have this work so I can use it on very large sessions.
An even better script would be one that swaps the Comments & Track Names.
Are you seeing an error?
What happens when you run this script?
It works on one selected track. I want it to work on multiple selected tracks.
How were you running this script?
I used a keyboard shortcut within the target app
How important is this issue to you?
2
Details
{ "inputExpected": "I want to be able to rename tracks with the comments field. Here's the scenario: \n\nI'm working on a large session that has lots of weird naming happening probably due to importing a lot of audio files with weird names, but I might need to retain those weird track names in order to use import session data at a later date.\n\nI have a script that will copy the track names to the Comments so that I can rename tracks in a way that makes sense. Now I'm looking to copy those names from the Comments back to the track name. I have a script where I can do this one track at a time, but I want to be able to select multiple tracks and have this work so I can use it on very large sessions.\n\nAn even better script would be one that swaps the Comments & Track Names.", "inputIsError": false, "inputWhatHappens": "It works on one selected track. I want it to work on multiple selected tracks.", "inputHowRun": { "key": "-Mpfwh4RkPLb2LPwjePT", "title": "I used a keyboard shortcut within the target app" }, "inputImportance": 2, "inputTitle": "Renaming Tracks with Comments" }
Source
var comments = sf.ui.proTools.selectedTrack.textFields.first.value.value;
log(comments);
sf.ui.proTools.selectedTrack.trackOpenRenameDialog({
renameAllSelectedTracks: true,
});
sf.keyboard.type({
text: comments,
});
sf.ui.proTools.focusedWindow.buttons.whoseTitle.is("OK").first.elementClick();
Links
User UID: cLPQQlgA6SX7DSnymqYDcm58oeu1
Feedback Key: sffeedback:cLPQQlgA6SX7DSnymqYDcm58oeu1:-MuSJ3PIWY3DgqO1HIt7
Linked from:
- Raphael Sepulveda @raphaelsepulveda2022-01-27 21:20:05.386Z
This should do!
function renameTracksWithComments() { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.mainWindow.invalidate(); const selectedTrackNames = sf.ui.proTools.selectedTrackNames; sf.ui.proTools.trackDeselectAll(); selectedTrackNames.forEach(selectedTrackName => { const selectedTrack = sf.ui.proTools.trackGetByName({ name: selectedTrackName }).track; selectedTrack.trackScrollToView(); const comments = selectedTrack.textFields.first.value.value; if (comments) selectedTrack.trackRename({ newName: comments }); }); } renameTracksWithComments();
- NNenad Simsic @Nenad_Simsic
This works very well and fast! Even in 2023.6. Is there a way to make this script other way around so that Comment gets the name of the selected Track(s)?
Raphael Sepulveda @raphaelsepulveda2023-06-19 16:21:01.099Z2023-06-21 15:54:46.702Z
@Nenad_Simsic, sure thing!
EDIT: This is the latest version of the
fillCommentsWithSelectedTrackNames
script 👇🏼/** @param {{ overwriteExistingComments?: boolean }} args */ function fillCommentsWithSelectedTrackNames({ overwriteExistingComments } = {}) { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.mainWindow.invalidate(); sf.ui.proTools.selectedTracks.trackHeaders.forEach(track => { const trackName = track.normalizedTrackName; const commentsTextField = track.textFields.whoseTitle.startsWith("Comments").first; const hasComments = !commentsTextField.title.value.endsWith('""'); commentsTextField.elementClick(); // Scrolls track into view as a side effect if (overwriteExistingComments && hasComments) { sf.keyboard.press({ // Delete comments keys: "cmd+a, backspace", }); } commentsTextField.elementSetTextFieldWithAreaValue({ useMouseKeyboard: true, value: trackName + (hasComments ? " " : "") }); }); sf.keyboard.press({ keys: "return" }); // Removes comment textfield focus from last track } fillCommentsWithSelectedTrackNames({ overwriteExistingComments: true });
- NNenad Simsic @Nenad_Simsic
Thank you very much Raphael!
- In reply toraphaelsepulveda⬆:NNenad Simsic @Nenad_Simsic
Hey Raphael, I've noticed that the script actually adds the track name to existing comment; is there a line that I could add or change to completely overwrite the comments?
Raphael Sepulveda @raphaelsepulveda2023-06-19 22:45:34.007Z
Yeah, I just updated the previous script to do that.
Use that script and replace the last line with this one to turn on the overwrite feature:fillCommentsWithSelectedTrackNames({ overwriteExistingComments: true });
- NNenad Simsic @Nenad_Simsic
Somehow it doesn't overwrite the comments, instead writes a name in front of the existing one.
here is how it looks like:
/** @param {{ overwriteExistingComments?: boolean }} args */
function fillCommentsWithSelectedTrackNames({ overwriteExistingComments } = {}) {
sf.ui.proTools.appActivateMainWindow();
sf.ui.proTools.mainWindow.invalidate();sf.ui.proTools.selectedTrackNames.forEach(selectedTrackName => { const track = sf.ui.proTools.trackGetByName({ name: selectedTrackName }).track; const commentsTextField = track.textFields.whoseTitle.startsWith("Comments").first; const hasComments = !commentsTextField.title.value.endsWith('""'); commentsTextField.elementClick(); // Scrolls track into view as a side effect if (overwriteExistingComments && hasComments) { sf.keyboard.press({ // Delete comments keys: "cmd+a, backspace", }); } commentsTextField.elementSetTextFieldWithAreaValue({ useMouseKeyboard: true, value: selectedTrackName + (hasComments ? " ": "") }); }); sf.keyboard.press({ keys: "return" }); // Removes comment textfield focus from last track
}
fillCommentsWithSelectedTrackNames({
overwriteExistingComments: true
});- NNenad Simsic @Nenad_Simsic
oops, didn't go well with pasting the script but it's all there.
- NNenad Simsic @Nenad_Simsic
Also if I select more than one track it just writes the first comment and throws an error
Raphael Sepulveda @raphaelsepulveda2023-06-20 16:40:35.344Z
Mmm.. that's odd.
Could you do a screen capture showing the script failing? Maybe I'll be able to identify the issue there.- NNenad Simsic @Nenad_Simsic
Hi Raphael, do you mean video capture? I also posted above error code.
is this script working on your system? With PT 2023.6?Raphael Sepulveda @raphaelsepulveda2023-06-20 19:58:18.853Z
Yes, a screen/video recording like this one:
https://www.dropbox.com/s/uq641y1uncne75w/SF Fill Comments with Selected Track Names Script Demo.mov?dl=0That's the script running in PT 2023.6.
The error you posted is helpful but I'd like a bit more context. The recording will help make it easier to spot any more clues on why it's failing.
- NNenad Simsic @Nenad_Simsic
I just made a video and sure thing, it worked (almost). It does overwrite existing comment but it throws error if I have more than one selected track. Here is a link https://www.dropbox.com/scl/fi/k2g3dff3nxa1202vg0lgt/NENAD-ScCap_Track-Name-to-Comment.mov?dl=0&rlkey=1ekum7chkheoxscqhd88em22d
Raphael Sepulveda @raphaelsepulveda2023-06-20 21:25:30.924Z
Perfect! The culprit was the track numbers and your video allowed me to repro and fix the issue.
I've updated the script at the top. It should be the one!- NNenad Simsic @Nenad_Simsic
Thank you Raphael, just copied the script but looks to me that the SF server is not well? Can't start the SoundFlow anymore...I'll try tomorrow and let you know how it goes
- In reply toraphaelsepulveda⬆:NNenad Simsic @Nenad_Simsic
It's all working now, big thanks Raphael!!
- In reply toDavid_Stagl⬆:David Stagl @David_Stagl
That works fantastic! Thank you so much, @raphaelsepulveda!
Raphael Sepulveda @raphaelsepulveda2022-01-27 21:32:03.302Z
My pleasure. Enjoy!