Repeat a script for a pre defined number of times
Hey all. I have a script that flies around the timeline on the tracks and selects and renames clips. I'd like to run it multiple times without having to hit the trigger each individual time. Is there a way to have it run multiple times depending on the amount of clips currently selected?
sf.keyboard.press({
keys: "tab, shift+tab, cmd+shift+r",
});
/* sf.ui.proTools.windows.whoseTitle.is('Name').first.elementWaitFor(); */
sf.keyboard.press({
keys: "cmd+c",
});
sf.wait({
intervalMs: 333,
});
sf.keyboard.press({
keys: "numpad enter",
});
sf.wait({
intervalMs: 333,
});
sf.keyboard.press({
keys: "semicolon, b",
});
sf.keyboard.press({
keys: "cmd+shift+r, t, a, l, e, n, t, shift+minus, cmd+v",
});
sf.keyboard.press({
keys: "return",
});
sf.wait({
intervalMs: 333,
});
sf.keyboard.press({
keys: "p, tab",
});
- Kitch Membery @Kitch2020-10-21 20:54:58.886Z
Hi @Chip_Sloan,
Check out this post here; https://forum.soundflow.org/-2989#post-3
It shows you how to create a for loop.
Let me know if you get stuck :-)
Chip Sloan @ChipSloan
Cool. That does help. Thank you. Much like where that post leaves off what are those commands Christian mentions that has it stop when no more clips remain?
- In reply toChipSloan⬆:Chip Sloan @ChipSloan
Specifically I'd love to first select all the clips. Then tell SF to learn how many clips I have selected and var that to become the number of loops.
Certainly this can be done by you wizards with the know how. I'm quite a rookie...
Kitch Membery @Kitch2020-10-21 22:15:40.947Z
Hey Chip!
This can be done by using the
sf.ui.Pro Tools.clipDoForEachClip()
method.BTW, I've re-written up your script in a way to uses the least amount of keyboard automation code, as it is the least stable way to write a script in SoundFlow. Instead I have used
menuClick
among other things.Here it is;
function copyAndAddSuffix() { //Copy Clip sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Copy'] }); //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog const nameDlg = sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Get the Clip name into a variable let clipName = nameDlg.groups.whoseTitle.is('Name').first.textFields.first.value.invalidate().value; //Close Rename Dialog nameDlg.buttons.whoseTitle.is('OK').first.elementClick(); //Create a marker sf.keyboard.press({ keys: "numpad enter", }); //Wait for the Markers dialog sf.ui.proTools.newMemoryLocationDialog.elementWaitFor(); //Insert text into the Marker name field sf.ui.proTools.newMemoryLocationDialog.textFields.allItems[1].elementSetTextFieldWithAreaValue({ value: clipName }); //Close the Marker dialog sf.ui.proTools.newMemoryLocationDialog.buttons.whoseTitle.is('OK').first.elementClick(); //Wait for the Markers dialog to disappear sf.ui.proTools.newMemoryLocationDialog.elementWaitFor({ waitType: 'Disappear' }); //Go to the track below sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Down'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Top'] }); //Clear selection sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Clear'] }); //Paste Clip sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] }); //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Enter text into the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.first.textFields.first.elementSetTextFieldWithAreaValue({ value: clipName + '_talent', }); //Close Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick(); //Go to the track above sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Up'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Bottom'] }); } function main() { sf.ui.proTools.clipDoForEachClip({ action: copyAndAddSuffix, onError: 'Continue' }) } main();
Hope that helps :-)
Christian Scheuer @chrscheuer2020-10-23 13:26:08.341Z
Make sure to check @Kitch's great video here that showcases how to do repetitive actions for each selected clip:
- In reply toChipSloan⬆:Chip Sloan @ChipSloan
Thanks Awesome. I had planned on going back and finding ways to make it far more efficient. You saved me a ton of work. I'm going to tweak it to then go back and remove the little bits in between. Should be fun. Thank you!!
Kitch Membery @Kitch2020-10-21 23:09:04.011Z
Rock on!!!
- In reply toChipSloan⬆:Chip Sloan @ChipSloan
Kitch,
Okay, this script is close but not what I'm after. the problem is the way you built it it copies that original file and pastes and renames it. Essentially making 2 dupllicate files. What I need it to do is ONLY copy and add a prefix to the name of the top track file. The file below needs to be chopped out but should not have it's content replaced. The whole point is to take that lower track which is of a higher resolution and cut out the same cliip lenghts and names as the above track. I'll try to evolve it and if I get it I'll post it...
Kitch Membery @Kitch2020-10-22 02:37:43.777Z
Ahhh I see what you were after. I should have asked for more info before I posted. :-)
- In reply toChipSloan⬆:Chip Sloan @ChipSloan
Okay, I modifed it to make it work the way I was planning. So, if anyone needs this in the futre there's that option above or this one that leaves the 2 tracks as unique audio named the same, with a prefix.
//Copy Clip // sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Copy'] }); //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog const nameDlg = sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Get the Clip name into a variable let clipName = nameDlg.groups.whoseTitle.is('Name').first.textFields.first.value.invalidate().value; //Close Rename Dialog nameDlg.buttons.whoseTitle.is('OK').first.elementClick(); //Create a marker sf.keyboard.press({ keys: "numpad enter", }); //Wait for the Markers dialog sf.ui.proTools.newMemoryLocationDialog.elementWaitFor(); //Insert text into the Marker name field sf.ui.proTools.newMemoryLocationDialog.textFields.allItems[1].elementSetTextFieldWithAreaValue({ value: clipName }); //Close the Marker dialog sf.ui.proTools.newMemoryLocationDialog.buttons.whoseTitle.is('OK').first.elementClick(); //Wait for the Markers dialog to disappear sf.ui.proTools.newMemoryLocationDialog.elementWaitFor({ waitType: 'Disappear' }); //Go to the track below sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Down'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Top'] }); //Clear selection //sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Clear'] }); //Paste Clip //sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Paste'] }); sf.ui.proTools.menuClick({ menuPath: ["Edit","Separate Clip","At Selection"], }); //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Enter text into the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.first.textFields.first.elementSetTextFieldWithAreaValue({ value: 'talent_' + clipName, }); //Close Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick(); //Go to the track above sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Up'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Bottom'] }); } function main() { sf.ui.proTools.clipDoForEachClip({ action: copyAndAddSuffix, onError: 'Continue' }) } main();
Kitch Membery @Kitch2020-10-22 02:44:53.800Z
Hi Chip,
It seems you were missing the first part of the script. Here is a fixed version.
function addSuffix() { //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog const nameDlg = sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Get the Clip name into a variable let clipName = nameDlg.groups.whoseTitle.is('Name').first.textFields.first.value.invalidate().value; //Close Rename Dialog nameDlg.buttons.whoseTitle.is('OK').first.elementClick(); //Create a marker sf.keyboard.press({keys: "numpad enter"}); //Wait for the Markers dialog sf.ui.proTools.newMemoryLocationDialog.elementWaitFor(); //Insert text into the Marker name field sf.ui.proTools.newMemoryLocationDialog.textFields.allItems[1].elementSetTextFieldWithAreaValue({ value: clipName }); //Close the Marker dialog sf.ui.proTools.newMemoryLocationDialog.buttons.whoseTitle.is('OK').first.elementClick(); //Wait for the Markers dialog to disappear sf.ui.proTools.newMemoryLocationDialog.elementWaitFor({ waitType: 'Disappear' }); //Go to the track below sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Down'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Top'] }); //Separate at Selection sf.ui.proTools.menuClick({ menuPath: ["Edit", "Separate Clip", "At Selection"], }); //Open the Rename Dialog sf.ui.proTools.menuClick({ menuPath: ['Clip', 'Rename...'] }); //Wait for the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').waitFor().element //Enter text into the Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.groups.first.textFields.first.elementSetTextFieldWithAreaValue({ value: 'talent_' + clipName, }); //Close Rename Dialog sf.ui.proTools.windows.whoseTitle.is('Name').first.buttons.whoseTitle.is('OK').first.elementClick(); //Go to the track above sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Extend Edit Up'] }); sf.ui.proTools.menuClick({ menuPath: ['Edit', 'Selection', 'Remove Edit from Bottom'] }); } function main() { sf.ui.proTools.clipDoForEachClip({ action: addSuffix, onError: 'Continue' }) } main();
Rock on