No internet connection
  1. Home
  2. Support

Renaming Tracks with Comments

By David Stagl @David_Stagl
    2022-01-27 20:53:11.515Z

    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

    Feedback ZIP

    Solved in post #2, click to view
    • 18 replies
    1. 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();
      
      Reply1 LikeSolution
      1. NNenad Simsic @Nenad_Simsic
          2023-06-19 11:39:22.565Z

          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)?

          1. 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
            });
            
            1. NNenad Simsic @Nenad_Simsic
                2023-06-19 20:29:34.046Z

                Thank you very much Raphael!

                1. NNenad Simsic @Nenad_Simsic
                    2023-06-19 22:17:26.827Z

                    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?

                    1. 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
                      });
                      
                      1. NNenad Simsic @Nenad_Simsic
                          2023-06-20 07:50:28.666Z

                          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
                          });

                          1. NNenad Simsic @Nenad_Simsic
                              2023-06-20 07:51:45.632Z

                              oops, didn't go well with pasting the script but it's all there.

                              1. NNenad Simsic @Nenad_Simsic
                                  2023-06-20 07:55:57.968Z

                                  Also if I select more than one track it just writes the first comment and throws an error

                                  1. Mmm.. that's odd.
                                    Could you do a screen capture showing the script failing? Maybe I'll be able to identify the issue there.

                                    1. NNenad Simsic @Nenad_Simsic
                                        2023-06-20 18:49:55.258Z

                                        Hi Raphael, do you mean video capture? I also posted above error code.
                                        is this script working on your system? With PT 2023.6?

                                        1. 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=0

                                          That'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.

                                          1. NNenad Simsic @Nenad_Simsic
                                              2023-06-20 20:56:18.578Z

                                              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

                                              1. 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!

                                                1. NNenad Simsic @Nenad_Simsic
                                                    2023-06-20 21:58:38.504Z

                                                    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

                                                    1. NNenad Simsic @Nenad_Simsic
                                                        2023-06-21 07:54:03.636Z

                                                        It's all working now, big thanks Raphael!!

                              2. In reply toDavid_Stagl:
                                David Stagl @David_Stagl
                                  2022-01-27 21:30:47.840Z

                                  That works fantastic! Thank you so much, @raphaelsepulveda!

                                  1. My pleasure. Enjoy!