Hello lovely soundflow Peeps!
I am trying to create a script that will group selected clips and then rename the clip group with the parent file name of the first selected clip. I have the following:
sf.ui.proTools.menuClick({
menuPath: ["Clip","Rename..."],
});
//wait for the window to open
sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor();
//Get the Parent File name
var parentName = sf.ui.proTools.windows.whoseTitle.is("Name").first.groups.whoseTitle.is("Clip Info").first.children.whoseRole.is("AXStaticText").allItems[2].value.invalidate().value;
log (parentName);
sf.ui.proTools.windows.whoseTitle.is("Name").first.buttons.whoseTitle.is("Cancel").first.elementClick();
sf.ui.proTools.menuClick({
menuPath: ["Clip","Group"],
});
sf.ui.proTools.menuClick({
menuPath: ["Clip","Rename..."],
});
sf.ui.proTools.windows.whoseTitle.is("Name").first.groups.whoseTitle.is("Name").first.textFields.whoseTitle.is("").first.elementClick();
sf.keyboard.type({
text: "hello",
});
sf.ui.proTools.windows.whoseTitle.is("Name").first.buttons.whoseTitle.is("OK").first.elementClick();
Now what I'm trying to do is figure out how I can access parentName
as a string to input into the clipgroup rename window. I was trying to use the 'type text' or 'set clipboard text' actions, but cant figure out a good way to access the variable. Any tips?
So I would be replacing this bit of code:
sf.keyboard.type({
text: "hello",
Thanks!
Max
- samuel henriques @samuel_henriques
I'm away from my computer, but I think I can explain.
After the second "clip rename" use the macro "set text field with text value" (something like this) and use the variable parentName as the text to input.
Then just "copy as javaScript" and paste it on your code, replacing the last two actions.In a few hours I'll be back and can help you more if you get stuck
samuel henriques @samuel_henriques
Hello @Maxwell_Smith,
Be aware that the name you get from the rename window, when you select several clips, might not be the first selected clip. In pro tools it is the first alphabetically, you can see the on the clip list.
here you go, you were almost there:
sf.ui.proTools.appActivateMainWindow() //Clip Rename sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."] }); //wait for the window to open and make it into a variable const renameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor().element //Get the Parent File name const parentName = renameWin.groups.whoseTitle.is("Clip Info").first.children.whoseRole.is("AXStaticText").allItems[2].value.invalidate().value //Cancel renameWin.buttons.whoseTitle.is("Cancel").first.elementClick(); renameWin.elementWaitFor({ waitType: "Disappear" }) // Clip Group sf.ui.proTools.menuClick({ menuPath: ["Clip", "Group"] }); //Clip Rename sf.ui.proTools.menuClick({ menuPath: ["Clip", "Rename..."] }); renameWin.elementWaitFor({ waitType: "Appear" }) // Set name, the parentName variable, without file extention for example ".wav" renameWin.groups.whoseTitle.is("Name").first.textFields.whoseTitle.is("").first.elementSetTextFieldWithAreaValue({ value: parentName.split(".").slice(0,-1).join("."), }); // Ok renameWin.buttons.whoseTitle.is("OK").first.elementClick(); renameWin.elementWaitFor({ waitType: "Disappear" })
- MMaxwell Smith @Maxwell_Smith
Thank you so much, Samuel!
So you have to make the name window into a variable in order to access it later? And why "const" rather than "var"?
Side question... why do you have to add the wait for window functions? Just a safety if pro tools lags?
Thanks again for the speedy response! You're help is greatly appreciated.
Best,
Maxsamuel henriques @samuel_henriques
Awesome, it's working.
So you have to make the name window into a variable in order to access it later?
I made the whole window into a variable just so you don't need to keep repeating the line, so:
const renameWin = sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor().element
not only gets the "Name" window, it also waits for it. Then you can keep using
renameWin
instead ofsf.ui.proTools.windows.whoseTitle.is('Name').first
all the time.From there you can get to the elements inside the window as well, (this one you had already, I just made it shorter):
//Get the Parent File name const parentName = renameWin.groups.first.textFields.first.value.invalidate().value;
And why "const" rather than "var"?
Here's a really good explanation I got when I asked the same question:
Kitch rocks!!!
why do you have to add the wait for window functions? Just a safety if pro tools lags?
exactly, I tend to get these bits mostly as safety, and with my short experience, I learned the hard way, that sometimes something doesn't work, and I spend hours trying to figure it out just to find it was something as simple as this. So I think it's a good, specially when it is so simple. Some times it's not.
Have fun!!
- In reply tosamuel_henriques⬆:MMaxwell Smith @Maxwell_Smith7
Hey Samuel! Actually on closer look, it looks like the clip group is being renamed w/ the clip name and not the parent file name, which I was accessing with this line:
var parentName = sf.ui.proTools.windows.whoseTitle.is("Name").first.groups.whoseTitle.is("Clip Info").first.children.whoseRole.is("AXStaticText").allItems[2].value.invalidate().value;
Any way for this to be re-worked to use the Parent File Name?
samuel henriques @samuel_henriques
Sorry, completely missed that, I changed it for the actual clip name, that's why I was saying you would get the first name from clip list.
That makes more sense. I'm away from my computer now, but just replacing that line with the one I sent starting "const parentName", should work the same way but with the correct parentName.I'll double check as soon as I'm back.
- In reply toMaxwell_Smith7⬆:
samuel henriques @samuel_henriques
Just updated above and added a part to remove the file extension from the name.
Let me know if this is it.