No internet connection
  1. Home
  2. Macro and Script Help

Copy Current Selection Timecode In/Out from Pro Tools to the Clipboard as Text

By Jeremiah Moore @Jeremiah_Moore
    2023-02-23 00:34:34.166Z2023-02-23 07:35:09.433Z

    Hi all -

    I've got a specific script I want to make. This is easy in Keyboard Maestro, but I don't know how to do it here as I can't figure out how to manipulate multiple bits of text into the clipboard.

    Script function is: copy at Pro Tools TC in/out points to clipboard in the format: "06:04:06:08 - 06:04:06:16"

    Use case: making a selection in PT, activate script, then paste TC range into a note or email.
    Optional variant: add a dash-space to top, and two spaces to end of output format: "- 06:04:06:08 - 06:04:06:16 "
    this allows for pasting into some notes formats which turns the item into a bullet point.

    Pseudocode:

    • activate Pro Tools
    • type "/" , super tiny pause, then "cmd-C" (enter timecode in field, copy to clipboard)
    • (?how?) store contents of clipboard to variable string
    • type "//", super tiny pause, then "cmd-C" (enter timecode OUT field, copy to clipboard)
    • (?how?) append " - " to variable string
    • (?how?) append current clipboard to variable string
    • (?how?) copy variable string to clipboard then discard variable string.

    result: clipboard now has formatted text of Pro Tools in/out timecodes in it.

    I've fiddled around for a good half hour and can't figure out anything that works.
    decided to try in Keyboard maestro, and had it done in about six minutes.
    thoughts?

    Solved in post #5, click to view
    • 25 replies

    There are 25 replies. Estimated reading time: 14 minutes

    1. J
      Jeremiah Moore @Jeremiah_Moore
        2023-02-23 00:35:28.203Z

        screenshot of my KM script here: https://capture.dropbox.com/iMjNYRx8kCIHBQu1

        1. JJeremiah Moore @Jeremiah_Moore
            2023-02-23 21:22:46.611Z

            hey - @Kitch @Christian_Scheuer3 - any thoughts on this?

            Maybe it's necessary to use javascript to access variables? (or maybe there's a way to accomplish this without variables...)

            1. Kitch Membery @Kitch2023-02-23 22:26:01.277Z

              Hi @Jeremiah_Moore,

              I'll take a look shortly. Much can be improved by using UI automation rather than Keyboard simulation for workflows like this.

              Rock on!

          • In reply toJeremiah_Moore:
            Kitch Membery @Kitch2023-02-23 22:40:04.493Z

            Hi @Jeremiah_Moore,

            This should do the trick

            //Activate Pro Tools Main Window  - Optional Step
            sf.ui.proTools.appActivateMainWindow();
            
            //Get the selections in & out points.
            const selection = sf.ui.proTools.selectionGet();
            
            //Format the Timecode in and out string " - " + Timecode in point + " - " + Timecode out point + " "
            let timecodeInAndOut = ` - ${selection.selectionStart} - ${selection.selectionEnd} `;
            
            //Store the Timecode in and out string into the clipboard.
            sf.clipboard.setText({
                text: timecodeInAndOut,
            });
            

            The great thing about this script is that it requires no Keyboard simulation and does things in the background. Just run the script and the Timecode information will be in your clipboard.

            Note: This script assumes your main counter is set to Timecode already.

            I hope that helps. :-)

            Reply1 LikeSolution
            1. JJeremiah Moore @Jeremiah_Moore
                2023-02-23 23:26:11.563Z

                Fantastic! Yes precisely. Thx @Kitch

                Obviously Javascript is where the power tools are... pretty much exactly what I wanted to do (could almost make a person want to learn a little javascript)

                (It's got me thinking about one more thing I'd like to accomplish, to do with selecting a clip or section of clips, and moving the selection up or down the tracks using keys.)

                -jeremiah

                1. In reply toKitch:
                  Ddanielkassulke @danielkassulke
                    2023-04-19 06:56:31.010Z

                    Hi Kitch!

                    Quick Q: I'm hoping to be able to automate the calculation of HW insert delays with this, among other things. The value will obviously always be in milliseconds - is there a way to capture the timecode selection but ignore (i.e. not copy) the HH:MM component of that value when copying to the clipboard?

                    1. Kitch Membery @Kitch2023-04-19 07:12:58.615Z

                      Hi @danielkassulke,

                      So are you trying to get the length of a selection in samples?

                      1. Ddanielkassulke @danielkassulke
                          2023-04-19 07:32:12.716Z

                          Hi Kitch,

                          No - at least I don't think so. I've modified the above script to get value in H:MM:SS already. The HW delay value [Setup > I/O > H/W Insert Delay] is in milliseconds. The issue I'm running into is that the main counter's length value and the H/W insert delay value - while both in milliseconds - are displayed differently if you paste from the clipboard, so I'm unsure how to reconcile that difference. The H/W insert delay value shows 0.00 in ms.

                          1. Kitch Membery @Kitch2023-04-19 07:38:00.419Z

                            I think I understand, so what you need to get a selection length in 0.00 ms format?

                            1. Ddanielkassulke @danielkassulke
                                2023-04-19 07:39:50.056Z

                                exactly!

                                1. Kitch Membery @Kitch2023-04-19 07:43:28.925Z

                                  Like this...

                                  function main() {
                                      // Get the selection
                                      const selection = sf.ui.proTools.selectionGet();
                                  
                                      // Get the selection length then remove HH:MM and convert to S.MS format
                                      const selectionLength = selection.selectionLength.split(":").slice(2).join(".");
                                  
                                      //Store the Timecode in and out string into the clipboard
                                      sf.clipboard.setText({ text: selectionLength, });
                                  }
                                  
                                  sf.ui.proTools.mainCounterDoWithValue({
                                      targetValue: "Timecode",
                                      action: main
                                  });
                                  

                                  UPDATED

                                  Let me know if that does the trick :-)

                                  1. Ddanielkassulke @danielkassulke
                                      2023-04-19 07:55:27.763Z

                                      It does most of the trick! I thought there might have been a PT rounding error, but I suspect there's something funky going on at line 6, based on your comment. It should actually be a value showing exclusively milliseconds. Sorry for the lack of clarity

                                      1. Kitch Membery @Kitch2023-04-19 08:03:21.764Z

                                        Hi @danielkassulke,

                                        To clarify... Are you trying to get the selection "length" as a value in milliseconds only?

                                        1. Ddanielkassulke @danielkassulke
                                            2023-04-19 08:12:02.531Z

                                            yup - a milliseconds-only value where 1.50 would be 1 1/2 milliseconds

                                            1. Kitch Membery @Kitch2023-04-19 08:20:41.847Z

                                              I think I'm confused again...

                                              So, if the timecode length reads "00:00:02:12" like this...

                                              Do you want "02.00" copied to the clipboard?

                                              1. Ddanielkassulke @danielkassulke
                                                  2023-04-19 08:40:11.359Z

                                                  I'm confused too!

                                                  Somehow we're looking at different length settings, but in my attached screenshot 0:00:010 is 10 milliseconds.

                                                  So copying the value in my screenshot, the clipboard should read: 10.00

                                                  1. Kitch Membery @Kitch2023-04-19 08:41:30.955Z

                                                    Great that makes way more sense. Stand by!

                                                    1. In reply todanielkassulke:
                                                      Kitch Membery @Kitch2023-04-19 08:45:01.708Z

                                                      I believe this is what you're after.

                                                      function main() {
                                                          const selectionLength = sf.ui.proTools.selectionGet().selectionLength;
                                                      
                                                          const [minutes, seconds, milliseconds] = selectionLength.split(/:|\./);
                                                      
                                                          const totalMilliseconds = (Number(milliseconds) + (Number(seconds) * 1000) + (Number(minutes) * 60 * 1000)).toFixed(2)
                                                      
                                                          sf.clipboard.setText({
                                                              text: totalMilliseconds.toString(),
                                                          });
                                                      }
                                                      
                                                      sf.ui.proTools.mainCounterDoWithValue({
                                                          targetValue: "Min:Secs",
                                                          action: main
                                                      });
                                                      
                                                      1. Ddanielkassulke @danielkassulke
                                                          2023-04-20 07:42:50.683Z

                                                          Sorry for totally derailing this post, Kitch - let me know if you want me to start a new thread for this. I'm not sure what's going on with the code, but here's a screen recording:

                                                          It's hard to pinpoint exactly what's happening because the text output of the totalMilliseconds string is 0.00. Yesterday you were most of the way there i think, but I think the decimal places were rounding the ms values up/down.

                                                          1. In reply todanielkassulke:
                                                            Kitch Membery @Kitch2023-04-20 08:27:10.828Z

                                                            Hi @danielkassulke

                                                            I'll take a look at this in the morning. :-)

                                                            1. In reply todanielkassulke:
                                                              Kitch Membery @Kitch2023-04-20 08:46:02.515Z

                                                              @danielkassulke, One last try before I head to bed. Hopefully this is it :-)

                                                              function timeToMs(timeStr) {
                                                                  const [minutes, secondsMs] = timeStr.split(":");
                                                                  const [seconds, milliseconds] = secondsMs.split(".");
                                                                  const totalMs = (+minutes * 60 + +seconds) * 1000 + +milliseconds;
                                                                  return totalMs;
                                                              }
                                                              
                                                              function main() {
                                                                  const selectionLength = sf.ui.proTools.selectionGet().selectionLength;
                                                                  let totalMilliseconds = timeToMs(selectionLength).toFixed(2);
                                                              
                                                                  log(totalMilliseconds);
                                                              
                                                                  sf.clipboard.setText({
                                                                      text: totalMilliseconds.toString(),
                                                                  });
                                                              }
                                                              
                                                              sf.ui.proTools.mainCounterDoWithValue({
                                                                  targetValue: "Min:Secs",
                                                                  action: main
                                                              });
                                                              

                                                              Note: line 12 is for logging purposes only. Feel free to comment it out, or remove it once you've tested it.

                                                              Be sure to create a new script and paste this code in and run it without any other code to check that it works. I it looks like you have other code running in the video you made.

                                  2. T
                                    In reply toJeremiah_Moore:
                                    T Francis @T_Francis
                                      2024-08-27 08:48:36.652Z

                                      Hi there! I've modified this script to create a version which just copies the current TC point into the clipboard:

                                      //Activate Pro Tools Main Window  - Optional Step
                                      sf.ui.proTools.appActivateMainWindow();
                                      
                                      //Get the selections in & out points.
                                      const selection = sf.ui.proTools.selectionGet();
                                      
                                      //Format the Timecode string
                                      let timecodeInAndOut = `${selection.selectionStart}`;
                                      
                                      //Store the Timecode string into the clipboard.
                                      sf.clipboard.setText({
                                          text: timecodeInAndOut,
                                      });
                                      

                                      It spits out a perfect 00:00:00:00 string. Is there a way of changing the format to 00.00.00.00 for a different document?

                                      Many Thanks!

                                      Trystan

                                      1. Ddanielkassulke @danielkassulke
                                          2024-08-28 02:18:23.759Z2024-12-26 08:39:36.862Z

                                          Try this:

                                          sf.ui.proTools.appActivateMainWindow();
                                          
                                          //Get the selections in & out points.
                                          const selection = sf.ui.proTools.selectionGet();
                                          
                                          //Format the Timecode string
                                          let timecodeInAndOut = `${selection.selectionStart}`;
                                          
                                          // Replace : with .
                                          timecodeInAndOut = timecodeInAndOut.replace(/:/g, '.');
                                          
                                          //Store the Timecode string into the clipboard.
                                          sf.clipboard.setText({
                                              text: timecodeInAndOut,
                                          });
                                          
                                          1. TT Francis @T_Francis
                                              2024-08-28 08:32:00.562Z

                                              Awesome, thankyou :)

                                              1. In reply todanielkassulke:
                                                TT Francis @T_Francis
                                                  2024-10-11 15:58:01.493Z

                                                  I've managed to sort this into a great script which copies the TC and Cue Name to the Clipboard and has saved loads of time!

                                                  sf.ui.proTools.mainWindow.invalidate();
                                                  ``
                                                  //Change Main Counter to Timecode
                                                  sf.ui.proTools.menuClick({ menuPath: ['View', 'Main Counter', 'Timecode'] });
                                                  
                                                  //Populate Text String
                                                  const sessionPath = sf.ui.proTools.mainWindow.sessionPath;
                                                  const sessionName = sessionPath.split("/").slice(-1)[0].split(".ptx")[0]
                                                  const selection = sf.ui.proTools.selectionGet();
                                                  
                                                  //Format the Timecode string
                                                  let currentTC = selection.selectionStart.split(':').join('.');
                                                  
                                                  //Construct Clipboard
                                                  const PopulateClipboard = `${sessionName} ${currentTC}`
                                                  
                                                  //Populate Clipboard
                                                  sf.clipboard.setText({
                                                      text: PopulateClipboard
                                                  });
                                                  

                                                  I have a question - is there any way to make the ruler switching conditional?

                                                  It'd be great if, when in Bars|Beats, the ruler switches to Timecode in order to populate the Clipboard, then switches BACK to Bars|Beats; however if already in Timecode view, it stays there once the clipboard is populated.

                                                  Do you think this is possible?

                                                  Continued thanks for your help!!

                                                  Trystan