No internet connection
  1. Home
  2. How to

Store Selected Track > Paste Clip on another track > Return to original track and make new playlist

By Joe Kearns @Joe_Kearns
    2024-03-22 10:25:05.856Z

    Hey!

    I have a script that is kind of working but it is a bit buggy and wondered if theres a better way?

    I basically want soundlflow to copy a selected clip on the selected track, jump to a specifically named track , paste, jump back to original track and then make a new playlist.
    My script seems to work the first time I switch from SF to PT windows but then not after? Am I doing some stupid or is there a fix for this? My script is below, much appreciated in advance!

    const firstSelectedTrackHeader = sf.proTools.trackGetFirstSelectedTrackHeader().firstSelectedTrackHeader;
    
    sf.ui.proTools.menuClick({
        menuPath: ["Edit","Copy"],
    });
    
    sf.ui.proTools.trackGetByName({ name: "vox vrs_lv tk.00", makeVisible: true }).track.trackSelect({
        executionMode: "Background",
        onCancel: "Abort",
    });
    
    sf.keyboard.press({
        keys: "left",
    });
    
    sf.ui.proTools.menuClick({
        menuPath: ["Edit","Paste"],
    });
    
    firstSelectedTrackHeader.trackSelect();
    
    sf.keyboard.press({
        keys: "ctrl+backslash, return",
    });
    
    • 15 replies

    There are 15 replies. Estimated reading time: 14 minutes

    1. Chris Shaw @Chris_Shaw2024-03-22 15:47:07.426Z2024-03-22 16:16:56.083Z

      Anytime you hide, create, or delete tracks or create new playlists the SF cache for the main window becomes out of date.
      You'll need to invalidate the main window, which invalidates the cache, each time you run the script.
      This is done by inserting the following at the top of your script:

      sf.ui.proTools.mainWindow.invalidate()
      

      It's always good practice to start all of your scripts and macros with this command.

      1. Chris Shaw @Chris_Shaw2024-03-22 16:08:51.384Z2024-03-22 16:17:31.423Z

        Additionally, it's best practice to avoid using keystrokes whenever possible.
        I've added code to click the playlist selector and select "New…" to create the new playlist.
        Instead of getting track headers you can just get the track name.
        I've also put the destination track name into a variable at the top of the script to make it easier to change the destination track at a later date

        const destinationTrack = "vox vrs_lv tk.00"
        
        sf.ui.proTools.mainWindow.invalidate()
        
        // Get source track name
        const selectedTrack = sf.ui.proTools.selectedTrackNames[0]
        
        // Copy audio
        sf.ui.proTools.menuClick({
            menuPath: ["Edit", "Copy"],
        });
        
        // Select the destination track
        sf.ui.proTools.trackSelectByName({names:[destinationTrack]})
        
        //Center clip in edit window
        sf.keyboard.press({
            keys: "left",
        });
        
        //Paste audio on destination track
        sf.ui.proTools.menuClick({
            menuPath: ["Edit", "Paste"],
        });
        
        // Re-select the source track
        sf.ui.proTools.trackSelectByName({names:[selectedTrack]})
        
        // Create new playlist 
        const playlistSelector = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Playlist selector").first;
        
        playlistSelector.popupMenuSelect({
            menuPath: ["New..."],
        });
        
        // Wait for playlist name dialog
        sf.ui.proTools.confirmationDialog.elementWaitFor();
        
        // Click OK in playlist name dialog
        sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();
        

        If you feel like making a more advanced version of this script you could convert it to a template which would allow you to make presets for different destination tracks.

      2. J
        In reply toJoe_Kearns:
        Joe Kearns @Joe_Kearns
          2024-03-25 20:21:38.851Z

          Thank you so much Chris. This is amazing. Works perfectly.

          Really Appreciate your knowledge and help!

          1. J
            In reply toJoe_Kearns:
            Joe Kearns @Joe_Kearns
              2024-03-25 20:34:12.020Z

              Chris, just putting this into a template as you suggested (never made one before). Im a bit unsure what to put for the 'Type' of parameter?

              I can't seem to find any info/videos on making templates, would greatly appreciate any insight!

              thanks again!

              1. Here's a video from a few years back about creating templates.
                https://www.facebook.com/soundflowapp/videos/633065107406660

                It runs a bit long. A new, more concise, video is in the works - right @Kitch? :)

                1. If you're free on Wednesday afternoon , you can join the weekly SF Zoom hangout and ask there.

                  Info here.
                  It's much easier to see than explain in a post:

                  1. In reply toChris_Shaw:
                    Kitch Membery @Kitch2024-03-25 21:50:17.188Z

                    Hi @Joe_Kearns,

                    It looks like you've watched the video, but if you're interested, here is an article on command templates. :-)

                    https://soundflow.org/docs/how-to/custom-commands/command-templates

                    I hope that helps.

                    1. JJoe Kearns @Joe_Kearns
                        2024-03-25 22:01:46.183Z

                        Thanks Kitch.

                        Had a quick look, some useful bits in there. But cant seem to solve my 'expected string but got object' issue when using 'AxPtTrackHeader' in the template type. Any ideas there please Kitch?

                        Code Below:

                        
                        const destinationTrack = event.props.destinationTrack;
                        
                        sf.ui.proTools.mainWindow.invalidate()
                        
                        // Get source track name
                        const selectedTrack = sf.ui.proTools.selectedTrackNames[0]
                        
                        // Copy audio
                        sf.ui.proTools.menuClick({
                            menuPath: ["Edit", "Copy"],
                        });
                        
                        // Select the destination track
                        sf.ui.proTools.trackSelectByName({names:[destinationTrack]})
                        
                        //Center clip in edit window
                        sf.keyboard.press({
                            keys: "left",
                        });
                        
                        //Paste audio on destination track
                        sf.ui.proTools.menuClick({
                            menuPath: ["Edit", "Paste"],
                        });
                        
                        // Re-select the source track
                        sf.ui.proTools.trackSelectByName({names:[selectedTrack]})
                        
                        // Create new playlist 
                        const playlistSelector = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Playlist selector").first;
                        
                        playlistSelector.popupMenuSelect({
                            menuPath: ["New..."],
                        });
                        
                        // Wait for playlist name dialog
                        sf.ui.proTools.confirmationDialog.elementWaitFor();
                        
                        // Click OK in playlist name dialog
                        sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();
                        
                        1. Kitch Membery @Kitch2024-03-25 22:12:20.628Z

                          You were so close.

                          Try this script...

                          const destinationTrackName = event.props.destinationTrackName;
                          
                          // Invalidate Pro Tools Main Windo in case tracks have changed.
                          sf.ui.proTools.mainWindow.invalidate();
                          
                          // Get source track name
                          const oldSelectedTrack = sf.ui.proTools.selectedTrackNames[0];
                          
                          // Copy selected aduio
                          sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
                          
                          // Select the destination track
                          sf.ui.proTools.trackSelectByName({ names: [destinationTrackName] });
                          
                          //Center clip in edit window
                          sf.keyboard.press({ keys: "left", });
                          
                          //Paste audio on destination track
                          sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"], });
                          
                          // Re-select the source track
                          sf.ui.proTools.trackSelectByName({ names: [oldSelectedTrack] });
                          
                          // Create new playlist 
                          const playlistSelector = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Playlist selector").first;
                          playlistSelector.popupMenuSelect({ menuPath: ["New..."], });
                          
                          // Wait for playlist name dialog
                          sf.ui.proTools.confirmationDialog.elementWaitFor();
                          
                          // Click OK in playlist name dialog
                          sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();
                          
                          // Wait for playlist name to disapear
                          sf.ui.proTools.confirmationDialog.elementWaitFor({waitType:"Disappear"});
                          

                          Then in the TEMPLATE tab, delete the destinationTrack property, and create a new one named destinationTrackName, then set its type to "String".

                          Create and customize a preset and run it.

                          Let me know if you need any further explanation. :-)

                          1. JJoe Kearns @Joe_Kearns
                              2024-03-25 22:17:09.883Z

                              Thanks Kitch,

                              that works perfect! However in a perfect world id love it if the preset could select the track from the SoundFlow track name selector thing that I get when I use 'AxPtTrackHeader'. This is because I want to make ALOT of presets here to work with my vocal recording template and having a track selector to choose them from would be really helpful!

                              Is there any 'AxPtTrackHeader' can work?

                              thanks again, really appreciate all the help from you and Chris on this one!

                              Joe.

                              1. Kitch Membery @Kitch2024-03-25 22:18:06.343Z

                                There is... Stand by :-)

                                1. In reply toJoe_Kearns:
                                  Kitch Membery @Kitch2024-03-25 22:23:57.714Z

                                  Try this...

                                  Delete the string property from the TEMPLATE tab and create a new property that looks like this.

                                  Then change the script to this.

                                  /** @type {AxPtTrackHeader} */
                                  const destinationTrack = event.props.destinationTrack;
                                  
                                  // Invalidate Pro Tools Main Windo in case tracks have changed.
                                  sf.ui.proTools.mainWindow.invalidate();
                                  
                                  // Get source track name
                                  const oldSelectedTrack = sf.ui.proTools.selectedTrackNames[0];
                                  
                                  // Copy selected aduio
                                  sf.ui.proTools.menuClick({ menuPath: ["Edit", "Copy"], });
                                  
                                  // Select the destination track
                                  destinationTrack.trackSelect();
                                  
                                  //Center clip in edit window
                                  sf.keyboard.press({ keys: "left", });
                                  
                                  //Paste audio on destination track
                                  sf.ui.proTools.menuClick({ menuPath: ["Edit", "Paste"], });
                                  
                                  // Re-select the source track
                                  sf.ui.proTools.trackSelectByName({ names: [oldSelectedTrack] });
                                  
                                  // Create new playlist 
                                  const playlistSelector = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Playlist selector").first;
                                  playlistSelector.popupMenuSelect({ menuPath: ["New..."], });
                                  
                                  // Wait for playlist name dialog
                                  sf.ui.proTools.confirmationDialog.elementWaitFor();
                                  
                                  // Click OK in playlist name dialog
                                  sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();
                                  
                                  // Wait for playlist name to disapear
                                  sf.ui.proTools.confirmationDialog.elementWaitFor({waitType:"Disappear"});
                                  

                                  Untested, but it should do the trick. :-)

                                  1. JJoe Kearns @Joe_Kearns
                                      2024-03-25 22:34:31.310Z

                                      it WORKS!

                                      thanks again so much.

                                      really appreciate the support!

                                      1. Kitch Membery @Kitch2024-03-25 22:35:10.503Z

                                        Awesome! Glad it worked @Joe_Kearns :-)

                        2. J
                          In reply toJoe_Kearns:
                          Joe Kearns @Joe_Kearns
                            2024-03-25 21:17:29.573Z

                            Thanks Chris,

                            just watched the video. Good Stuff!

                            I think im close to having it working except im getting the error 'expected string but got object'

                            I have used the Template type 'AxPtTrackHeader' in order for the preset to select the destination track. Is this correct?

                            And the code is:

                            const destinationTrack = event.props.destinationTrack;
                            
                            sf.ui.proTools.mainWindow.invalidate()
                            
                            // Get source track name
                            const selectedTrack = sf.ui.proTools.selectedTrackNames[0]
                            
                            // Copy audio
                            sf.ui.proTools.menuClick({
                                menuPath: ["Edit", "Copy"],
                            });
                            
                            // Select the destination track
                            sf.ui.proTools.trackSelectByName({names:[destinationTrack]})
                            
                            //Center clip in edit window
                            sf.keyboard.press({
                                keys: "left",
                            });
                            
                            //Paste audio on destination track
                            sf.ui.proTools.menuClick({
                                menuPath: ["Edit", "Paste"],
                            });
                            
                            // Re-select the source track
                            sf.ui.proTools.trackSelectByName({names:[selectedTrack]})
                            
                            // Create new playlist 
                            const playlistSelector = sf.ui.proTools.selectedTrack.popupButtons.whoseTitle.is("Playlist selector").first;
                            
                            playlistSelector.popupMenuSelect({
                                menuPath: ["New..."],
                            });
                            
                            // Wait for playlist name dialog
                            sf.ui.proTools.confirmationDialog.elementWaitFor();
                            
                            // Click OK in playlist name dialog
                            sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();