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?
- JJeremiah Moore @Jeremiah_Moore
screenshot of my KM script here: https://capture.dropbox.com/iMjNYRx8kCIHBQu1
- JJeremiah Moore @Jeremiah_Moore
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...)
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. :-)
- JJeremiah Moore @Jeremiah_Moore
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
- In reply toKitch⬆:Ddanielkassulke @danielkassulke
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?
Kitch Membery @Kitch2023-04-19 07:12:58.615Z
Hi @danielkassulke,
So are you trying to get the length of a selection in samples?
- Ddanielkassulke @danielkassulke
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.
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?
- Ddanielkassulke @danielkassulke
exactly!
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 :-)
- Ddanielkassulke @danielkassulke
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
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?
- Ddanielkassulke @danielkassulke
yup - a milliseconds-only value where 1.50 would be 1 1/2 milliseconds
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?
- Ddanielkassulke @danielkassulke
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
Kitch Membery @Kitch2023-04-19 08:41:30.955Z
Great that makes way more sense. Stand by!
- 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 });
- Ddanielkassulke @danielkassulke
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.
- In reply todanielkassulke⬆:
Kitch Membery @Kitch2023-04-20 08:27:10.828Z
I'll take a look at this in the morning. :-)
- 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.
- TIn reply toJeremiah_Moore⬆:T Francis @T_Francis
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
- Ddanielkassulke @danielkassulke
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, });
- TT Francis @T_Francis
Awesome, thankyou :)
- In reply todanielkassulke⬆:TT Francis @T_Francis
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