No internet connection
  1. Home
  2. How to

Incrementing a Duplicated Track Name

By TJ Allen @TJ_Allen
    2020-10-20 10:40:37.339Z

    Hey all,

    I'm loving what I'm starting to be able to do with Soundflow - and although I'm a total Java newbie and I'm very much bodging my way through it with bits of other scripts and macro's, I'm starting to get some great results.

    I've built a script that uses a little of @Andrew_Scheps 'Increment New Playlist' script and modifies it to apply to a duplicated track. It's working ok, although may be a little clunky. What I'm struggling with is how to get it to add a number if one doesn't exist already.

    So for example: "Fuzz Gtr 1" will be duplicated and the new name will be "Fuzz Gtr 2". However, if the original track was called "Fuzz Gtr" the script can't update the number. How could I have it check if a number exists, and if not, add it? Any help gratefully received!

    Cheers,
    Tim

    sf.ui.proTools.appActivateMainWindow();
    
    sf.ui.proTools.trackDuplicateSelected({
        duplicateActivePlaylist: false,
        duplicateAlternatePlaylists: false,
        duplicateAutomation: false,
    });
    
    //Remove .dup1 from existing name
    var oldTrackName = sf.ui.proTools.selectedTrackNames[0];
    var oldTrackName = oldTrackName.split('.').slice(0, -1).join('.');
    
    //Get and Increment Last Number
    function getAndIncrementLastNumber(str) {
        return str.replace(/\d+$/, function (s) {
            return ++s;
        });
    }
    
    //Variable for new track name
    var newTrackName = getAndIncrementLastNumber(oldTrackName);
    
    
    sf.ui.proTools.selectedTrack.trackOpenRenameDialog({
        renameAllSelectedTracks: false,
    });
    
    
    //Wait for Rename Track window to appear
    sf.ui.proTools.windows.first.elementWaitFor({ waitType: "Appear", });
    
    
    
    sf.ui.proTools.windows.first.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue
        ({ value: newTrackName });
    
    //Click OK in Rename Track window
    sf.ui.proTools.windows.first.buttons.whoseTitle.is('OK').first.elementClick();
    
    
    Solved in post #2, click to view
    • 16 replies
    1. I use this in my own workflow:

      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();
      
      ReplySolution
      1. TTJ Allen @TJ_Allen
          2020-10-20 13:33:32.562Z

          That's amazing - thanks Christian. So much sleeker than my clunky version!

          1. TTJ Allen @TJ_Allen
              2020-10-20 13:43:22.303Z

              This is working perfectly on all tracks except Instrument Tracks - is that a limitation of BulkRenameNumerical?

              It's logging:

              Could not bulk rename tracks (Numerical Duplicates: Line 17)
              Could not open Track Rename Dialog
              Could not right-click Track's Title Button
              Popup menu was not found
              Popup window was not found after waiting 2000 ms

              1. Yea that sounds like a limitation... I've logged a bug report for this.

                1. TTJ Allen @TJ_Allen
                    2020-10-20 14:18:05.685Z

                    Thanks Christian,

                    It's really amazing what Soundflow can do.

              2. In reply tochrscheuer:
                AAndrew Downes @Andrew_Downes
                  2020-10-21 03:43:48.133Z

                  Hi There

                  I would love to be able to apply this to Playlists. I can do it so long as there are numbers as a suffix in the track name, but haven't been able to add a nimber if there isn't one
                  Thanks

                  1. Hi Andrew,

                    Let's have that discussion in a separate thread :) It makes it easier for us to check which questions have been answered. I think the code needed for new playlists is quite different.

                    1. When I convert this script to a template I get an error: Expected boolean but got string - line 14. What I am doing wrong here?

                      const {
                      activePlaylist,
                      alternatePlaylists,
                      automation,
                      inserts,
                      sends,
                      groupAssignments,
                      afterLastSelectedTrack,
                      } = event.props

                      var numberOfDups = Number(prompt('How many duplicates?', '1'));

                      var originalTrackName = sf.ui.proTools.selectedTrackNames[0];
                      sf.ui.proTools.trackDuplicateSelected({
                      duplicateActivePlaylist: activePlaylist,
                      duplicateAlternatePlaylists: alternatePlaylists,
                      duplicateAutomation: automation,
                      duplicateGroupAssignments: groupAssignments,
                      duplicateInserts: inserts,
                      duplicateSends: sends,
                      insertAfterLastSelectedTrack: afterLastSelectedTrack,
                      numberOfDuplicates: numberOfDups
                      });

                      sf.ui.proTools.trackSelectByName({ names: [originalTrackName], deselectOthers: false });
                      sf.ui.proTools.selectedTrack.trackBulkRenameNumerical();

                      1. The enum members for each property are "true" and "false".

                        1. For this to work in a template you’ll have to use boolean when creating the props instead of User enums. Booleans will be displayed as “Yes” or “No” to the user in the template, but the value passed will be true or false.

                          1. Thats was an easy fix. Thanks!

                            1. One last issue. With folder tracks we now have a checkbox for "All Member Tracks", which is not implemented in the above code. I tried a few things, but couldn't bring up anything that looked correct for this - at least as Christian has coded it. I know other ways to do this, but is there a way to add this in this code?

                              1. Unfortunately no. :( The .trackDuplicateSelected() method is missing that property currently, so @chrscheuer would have to update it.

                                1. Got it. Maybe he can do that when he has a free second :)

                                  1. Hey guys. Please log this in Alpha/Beta Ideas so I don't forget it after the 4.2 release :)