Title
Import Audio From Multiple Folders
What do you expect to happen when you run the script/macro?
Session Prep: This will take a folder from finder containing audio files, create a Pro Tools session at the sample rate of the audio files within the selected folder, import my I/O, Template and the audio files then move the selected folder to the current Pro Tools session folder
Are you seeing an error?
What happens when you run this script?
I have this working perfectly for a single selected folder . 99% of the time when i am sent trackouts, the beat stems and vocal trackouts wet/dry are in different folders. I put all of those folders in one folder just for the sake of housekeeping. How could i get this to work in that scenario? Where the overall folder would be selected and audio would be imported from all of the subfolders?
How were you running this script?
I used a Stream Deck button
How important is this issue to you?
5
Details
{ "inputExpected": "Session Prep: This will take a folder from finder containing audio files, create a Pro Tools session at the sample rate of the audio files within the selected folder, import my I/O, Template and the audio files then move the selected folder to the current Pro Tools session folder\n", "inputIsError": false, "inputWhatHappens": "I have this working perfectly for a single selected folder . 99% of the time when i am sent trackouts, the beat stems and vocal trackouts wet/dry are in different folders. I put all of those folders in one folder just for the sake of housekeeping. How could i get this to work in that scenario? Where the overall folder would be selected and audio would be imported from all of the subfolders?", "inputHowRun": { "key": "-MpfwmPg-2Sb-HxHQAff", "title": "I used a Stream Deck button" }, "inputImportance": 5, "inputTitle": "Import Audio From Multiple Folders" }
Source
// Prompt for Trackouts Folder
let trackoutFolder = sf.ui.finder.selectedPaths[0]
//Get Folder Name FROM DOWNLOADS
let trackoutFolderName = sf.ui.finder.selectedPaths[0].split('/').slice(4, -1).join('/')
//Prompt for Session Name
let newSessionName = sf.interaction.displayDialog({
prompt: `Session Name`,
defaultAnswer: "",
buttons: ["Cancel", "OK"],
defaultButton: "OK",
}).text;
////////////////////////////////////////////////////////////////////////////////////////////////////
function getSampleRateFromAudioFile({ path }) {
function escapeCharacters(str) {
return str.replace(/([ *])/g, "\\$1");
}
const audioFileInfo = sf.system.exec({ commandLine: `afinfo ${escapeCharacters(path)}`}).result;
const match = audioFileInfo.match(/(\d{5,6}) Hz/);
if (!match) throw "Could not read sample rate from this file.";
const sampleRate = match[1];
return Number(sampleRate)/1000;
}
//Find and Select first .wav file in Folder
const audioPath = sf.file.directoryGetFiles({searchPattern: "*" + '.wav', path: sf.ui.finder.firstSelectedPath, isRecursive: true, }).paths[0]
const sampleRate = getSampleRateFromAudioFile({ path: audioPath});
////////////////////////////////////////////////////////////////////////////////////////////////////
function newSession() {
////////////////////////////////////////////////////////////////////////////////////////////////
function newSessionSetup() {
//Activate Pro Tools
sf.ui.proTools.appActivate();
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//Create New Session
sf.ui.proTools.menuClick({menuPath: ["File","Create New..."],});
//Reference Dashboard
const newSessionWin = sf.ui.proTools.windows.whoseTitle.is("Dashboard").first;
//Wait for Dashboard
newSessionWin.elementWaitFor({waitType: "Appear"});
//Enable Create From Template
newSessionWin.checkBoxes.whoseTitle.is("Create From Template").first.checkboxSet({ targetValue: "Disable",});
//Set Sample Rate
sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.allItems[2].popupMenuSelect({ menuPath: [`${sampleRate} kHz`],});
//Set Bit Depth
sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.allItems[3].popupMenuSelect({ menuPath: ['24-bit'],});
//Enter Session Name
newSessionWin.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: newSessionName, });
//Click Create
newSessionWin.buttons.whoseTitle.is("Create").first.elementClick();
};
////////////////////////////////////////////////////////////////////////////////////////////////
function newSessionLoc(){
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//Define Save Window
const saveWin = sf.ui.proTools.windows.whoseTitle.is("Save").first;
//Wait for Save Window
saveWin.elementWaitFor({waitType: "Appear"});
//Open 'Go' Sheet
sf.keyboard.type({ text: '/' });
//Wait for Sheet Window to Appear
saveWin.sheets.first.elementWaitFor({waitType: "Appear"});
//Set Destination
saveWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: '/Users/nathansalefski/Documents/Pro Tools Sessions',});
//Press Return
sf.keyboard.press({ keys: "return"});
//Wait
sf.wait({intervalMs: 250});
//Press Return
sf.keyboard.press({ keys: "return"});
//Wait
sf.wait({intervalMs: 250});
//Wait for Main Window to Appear
sf.ui.proTools.mainWindow.elementWaitFor({waitType: "Appear"})
};
////////////////////////////////////////////////////////////////////////////////////////////////
newSessionSetup(); newSessionLoc();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function importIO() {
//Define I/O Location
const iO = "/Users/nathansalefski/Documents/Pro Tools/IO Settings/NS JUL 2023 MAIN.pio"
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
// Make Reference to IO Window
const ioWindow = sf.ui.proTools.windows.whoseTitle.is("I/O Setup").first
//Open IO Window
sf.ui.proTools.menuClick({ menuPath: ["Setup", "I/O..."], });
//Wait for IO Window to Appear
ioWindow.elementWaitFor({waitType: "Appear"});
//Check "Apply to all tabs" Checkbox
ioWindow.checkBoxes.whoseTitle.is("Apply to all tabs").first.checkboxSet({ targetValue: "Enable",});
//Click Import Settings
ioWindow.buttons.whoseTitle.is("Import Settings...").first.elementClick();
const ioWin = sf.ui.proTools.windows.whoseTitle.is('Open').first;
//Wait for 'Open' Window
ioWin.elementWaitFor({waitType: "Appear"});
//Open 'Go' Sheet
sf.keyboard.type({ text: '/' });
//Wait for 'Go' Sheet Window to Appear
ioWin.sheets.first.elementWaitFor({waitType: "Appear"});
//Set Destination
ioWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${iO}`, });
//Press Return
sf.keyboard.press({ keys: "return", });
//Wait
sf.wait();
//Click Open
ioWin.buttons.whoseTitle.is('Open').first.elementClick();
//Wait for Confirmation Dialog
sf.ui.proTools.confirmationDialog.elementWaitFor({waitType: "Appear"});
//Click "Yes" in Confirmation Dialog
sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("Yes").first.elementClick();
//Wait for Confirmation Dialog to Disappear
sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: "Disappear", });
//Click "OK" in I/O Window
ioWindow.buttons.whoseTitle.is("OK").first.elementClick();
//Wait for I/O Window to Disappear
ioWindow.elementWaitFor({ waitType: "Disappear", });
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function importSessionData() {
//Define Template Location
const temp = "/Users/nathansalefski/Documents/Pro Tools Sessions/TEMPLATE/NS JULY 2023 MAIN.ptx"
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//Import Session Data
sf.ui.proTools.menuClick({ menuPath: ["File","Import","Session Data..."], });
//Define File Window
const fileWin = sf.ui.proTools.windows.whoseTitle.is("Open").first;
//Wait for 'Open' Window
fileWin.elementWaitFor({waitType: "Appear"});
//Open 'Go' Sheet
sf.keyboard.type({ text: '/' });
//Wait for 'Go' Sheet Window to Appear
fileWin.sheets.first.elementWaitFor({waitType: "Appear"});
//Set Destination
fileWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${temp}`, });
//Press Return
sf.keyboard.press({ keys: "return", });
//Wait
sf.wait();
//Click "Open"
fileWin.buttons.whoseTitle.is("Open").first.elementClick();
// Make Reference to Import Session Data Window
const iSDWin = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first
//Wait for Import Window
iSDWin.elementWaitFor({waitType: "Appear"});
//Option Click to Import all Tracks onto New Tracks
iSDWin.mouseClickElement({ relativePosition: {"x":185,"y":510}, isOption: true, });
//Click Window Configurations
iSDWin.groups.whoseTitle.is("Session Data").first.checkBoxes.whoseTitle.is("Window Configurations").first.checkboxSet({targetValue: 'Enable'});
// Click "Choose..."
iSDWin.groups.whoseTitle.is("Session Data").first.buttons.whoseTitle.is("Choose...").first.elementClick();
//Reference Track Data to Import Window
const trackData = sf.ui.proTools.windows.whoseTitle.is("Track Data to Import").first
//Wait for Track Data Window to Appear
trackData.elementWaitFor({waitType: "Appear"});
//Select Import Template from Dropdown Menu
trackData.children.whoseRole.is("AXMenuButton").whoseTitle.is("Librarian menu").first.popupMenuSelect({ menuPath: ["Import Template"], });
//Click "OK" in Track Data to Import Window
trackData.buttons.whoseTitle.is("OK").first.elementClick();
//Wait for Track Data Window to Disappear
trackData.elementWaitFor({waitType: "Disappear"});
//Click "OK" in Import Session Data Window
iSDWin.buttons.whoseTitle.is("OK").first.elementClick();
//Wait
sf.ui.proTools.waitForNoModals();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function importAudio() {
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//File, Import, Audio
sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], });
//Define Import Audio Window
const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first;
//Wait for 'Open' Window
openWin.elementWaitFor({waitType: "Appear"});
//Open 'Go' Sheet
sf.keyboard.type({ text: '/' });
//Wait for 'Go' Sheet Window to Appear
openWin.sheets.first.elementWaitFor({waitType: "Appear"});
//Set Destination
openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${trackoutFolder}`, });
//Press Return
sf.keyboard.press({ keys: "return",});
//Wait for 'Go' Sheet Window to Disappear
openWin.sheets.first.elementWaitFor({waitType: "Disappear"});
//Select All
sf.keyboard.press({ keys: "cmd+a",});
//Click "Copy"
openWin.buttons.whoseTitle.is("Copy ->").first.elementClick();
//Click "Open"
openWin.buttons.whoseTitle.is('Open').first.elementClick();
//Wait for 'Open' Window
openWin.elementWaitFor({waitType: "Appear"});
//Click "Open"
openWin.buttons.whoseTitle.is('Open').first.elementClick();
//Reference to Audio Import Options Window
const aIOWin = sf.ui.proTools.windows.whoseTitle.is("Audio Import Options").first
//Wait for 'Go' Sheet Window to Appear
aIOWin.elementWaitFor({waitType: "Appear"});
//Click "OK" to New Track
aIOWin.buttons.whoseTitle.is("OK").first.elementClick();
//Wait
sf.ui.proTools.waitForNoModals();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function moveToFolder() {
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//Move Tracks to New Folder
sf.ui.proTools.menuClick({ menuPath: ['Track', 'Move to New Folder...'],});
//Define Folder Window
const folderWin = sf.ui.proTools.windows.whoseTitle.is("Move To New Folder").first
//Wait for Folder Window to Appear
folderWin.elementWaitFor({waitType: "Appear"})
//Click Create
folderWin.buttons.whoseTitle.is("Create").first.elementClick()
//Wait for Folder Window to Disappear
folderWin.elementWaitFor({waitType: "Disappear"})
}
////////////////////////////////////////////////////////////////////////////////////////////////////
function main() {
//Activate Pro Tools and Refresh Cache
sf.ui.proTools.appActivate();
sf.ui.proTools.mainWindow.invalidate();
newSession();
importIO();
importSessionData();
importAudio();
//Save Session
sf.ui.proTools.menuClick({ menuPath: ["File","Save"],});
//Refresh Cache
sf.ui.proTools.mainWindow.invalidate();
//Define Session Folder
const sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/');
//Move Trackout Folder to Session Folder
sf.file.directoryMove({ sourcePath: trackoutFolder, destinationPath: `${sessionFolder}/${trackoutFolderName}`,});
}
main ();
Links
User UID: EoVu20w2ZRTvmJvgozc57ZXuAhU2
Feedback Key: sffeedback:EoVu20w2ZRTvmJvgozc57ZXuAhU2:-NcP9q7pXMikhF7b9aM5
- In reply tonathansalefski⬆:Nathan Salefski @nathansalefski
I tried adding this
function getFolders(selectedFolders) { const folderPath = sf.file.directoryGetDirectories({ path: selectedFolders, isRecursive: true,}).paths allPath.push(folderPath) } let allPath = [] sf.ui.finder.selectedPaths.forEach(getFolders)
modifying the import function:
function importAudio({path}) { //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //File, Import, Audio sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], }); //Define Import Audio Window const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Wait for 'Open' Window openWin.elementWaitFor({waitType: "Appear"}); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for 'Go' Sheet Window to Appear openWin.sheets.first.elementWaitFor({waitType: "Appear"}); //Set Destination openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: path}); //Press Return sf.keyboard.press({ keys: "return",}); //Wait for 'Go' Sheet Window to Disappear openWin.sheets.first.elementWaitFor({waitType: "Disappear"}); //Select All sf.keyboard.press({ keys: "cmd+a",}); //Click "Copy" openWin.buttons.whoseTitle.is("Copy ->").first.elementClick(); //Click "Convert" if (openWin.buttons.whoseTitle.is("Convert ->").first.exists) {openWin.buttons.whoseTitle.is("Convert ->").first.elementClick();} //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for 'Open' Window openWin.elementWaitFor({waitType: "Appear"}); //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Reference to Audio Import Options Window const aIOWin = sf.ui.proTools.windows.whoseTitle.is("Audio Import Options").first //Wait for 'Go' Sheet Window to Appear aIOWin.elementWaitFor({waitType: "Appear"}); //Click "OK" to New Track aIOWin.buttons.whoseTitle.is("OK").first.elementClick(); //Wait sf.ui.proTools.waitForNoModals(); }
and modifying the main function to this:
function main() { //Activate Pro Tools and Refresh Cache sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); newSession(); importIO(); importSessionData(); for (var i = 0; i < allPath.length; i++) {importAudio(allPath[i]); moveToFolder();} //Save Session sf.ui.proTools.menuClick({ menuPath: ["File","Save"],}); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Define Session Folder const sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/'); //Move Trackout Folder to Session Folder sf.file.directoryMove({ sourcePath: trackoutFolder, destinationPath: `${sessionFolder}/${trackoutFolderName}`,}); } main ();
Still no luck
Nathan Salefski @nathansalefski
@raphaelsepulveda any change you have time to tackle this?
Raphael Sepulveda @raphaelsepulveda2023-08-22 17:44:11.142Z
Sure thing.
Let's start by adding this to your list of functions:
function getFolders(path) { return sf.file.directoryGetDirectories({ path, isRecursive: true, }).paths }
Modify your
importAudio
function to this:/** @param {{ paths: string[] }} args */ function importAudio({ paths }) { //Define Import Audio Window const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Reference to Audio Import Options Window const aIOWin = sf.ui.proTools.windows.whoseTitle.is("Audio Import Options").first //File, Import, Audio sf.ui.proTools.menuClick({ menuPath: ["File", "Import", "Audio..."], }); //Wait for 'Open' Window openWin.elementWaitFor({ waitType: "Appear" }); paths.forEach(path => { //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for 'Go' Sheet Window to Appear openWin.sheets.first.elementWaitFor({ waitType: "Appear" }); //Set Destination openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: path }); //Press Return sf.keyboard.press({ keys: "return", }); //Wait for 'Go' Sheet Window to Disappear openWin.sheets.first.elementWaitFor({ waitType: "Disappear" }); //Select All sf.keyboard.press({ keys: "cmd+a", }); //Click "Copy" openWin.buttons.whoseTitle.is("Copy ->").first.elementClick(); //Click "Convert" if (openWin.buttons.whoseTitle.is("Convert ->").first.exists) { openWin.buttons.whoseTitle.is("Convert ->").first.elementClick(); } }); //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for 'Open' Window openWin.elementWaitFor({ waitType: "Appear" }); //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for 'Go' Sheet Window to Appear aIOWin.elementWaitFor({ waitType: "Appear" }); //Click "OK" to New Track aIOWin.buttons.whoseTitle.is("OK").first.elementClick(); //Wait sf.ui.proTools.waitForNoModals(); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); }
And finally, your
main
function:function main() { //Activate Pro Tools and Refresh Cache sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); newSession(); importIO(); importSessionData(); importAudio({ paths: getFolders(trackoutFolder) }); moveToFolder(); //Save Session sf.ui.proTools.menuClick({ menuPath: ["File", "Save"], }); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Define Session Folder const sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/'); //Move Trackout Folder to Session Folder sf.file.directoryMove({ sourcePath: trackoutFolder, destinationPath: `${sessionFolder}/${trackoutFolderName}` }); }
Nathan Salefski @nathansalefski
AMAZING! It's working! I rearranged a few things to have each folder that's imported be placed in a folder in Pro Tools. It's almost perfect. Is there anyway at all to name the Pro Tools folders according to which folder the audio was imported from? Here's where the script is currently:
// Prompt for Trackouts Folder let trackoutFolder = sf.ui.finder.selectedPaths[0] //Get Folder Name FROM DOWNLOADS let trackoutFolderName = sf.ui.finder.selectedPaths[0].split('/').slice(4, -1).join('/') //Prompt for Session Name let newSessionName = sf.interaction.displayDialog({ prompt: `Session Name`, defaultAnswer: "", buttons: ["Cancel", "OK"], defaultButton: "OK", }).text; //////////////////////////////////////////////////////////////////////////////////////////////////// function getFolders(path) { return sf.file.directoryGetDirectories({ path, isRecursive: true, }).paths} //////////////////////////////////////////////////////////////////////////////////////////////////// function getSampleRateFromAudioFile({ path }) { function escapeCharacters(str) { return str.replace(/([ *])/g, "\\$1"); } const audioFileInfo = sf.system.exec({ commandLine: `afinfo ${escapeCharacters(path)}`}).result; const match = audioFileInfo.match(/(\d{5,6}) Hz/); if (!match) throw "Could not read sample rate from this file."; const sampleRate = match[1]; return Number(sampleRate)/1000; } //Find and Select first .wav file in Folder const audioPath = sf.file.directoryGetFiles({searchPattern: "*" + '.wav', path: sf.ui.finder.firstSelectedPath, isRecursive: true, }).paths[0] const sampleRate = getSampleRateFromAudioFile({ path: audioPath}); //////////////////////////////////////////////////////////////////////////////////////////////////// function newSession() { //////////////////////////////////////////////////////////////////////////////////////////////// function newSessionSetup() { //Activate Pro Tools sf.ui.proTools.appActivate(); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Create New Session sf.ui.proTools.menuClick({menuPath: ["File","Create New..."],}); //Reference Dashboard const newSessionWin = sf.ui.proTools.windows.whoseTitle.is("Dashboard").first; //Wait for Dashboard newSessionWin.elementWaitFor({waitType: "Appear"}); //Enable Create From Template newSessionWin.checkBoxes.whoseTitle.is("Create From Template").first.checkboxSet({ targetValue: "Disable",}); //Set Sample Rate sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.allItems[2].popupMenuSelect({ menuPath: [`${sampleRate} kHz`],}); //Set Bit Depth sf.ui.proTools.windows.whoseTitle.is("Dashboard").first.popupButtons.allItems[3].popupMenuSelect({ menuPath: ['24-bit'],}); //Enter Session Name newSessionWin.textFields.whoseTitle.is('').first.elementSetTextFieldWithAreaValue({ value: newSessionName, }); //Click Create newSessionWin.buttons.whoseTitle.is("Create").first.elementClick(); }; //////////////////////////////////////////////////////////////////////////////////////////////// function newSessionLoc(){ //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Define Save Window const saveWin = sf.ui.proTools.windows.whoseTitle.is("Save").first; //Wait for Save Window saveWin.elementWaitFor({waitType: "Appear"}); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for Sheet Window to Appear saveWin.sheets.first.elementWaitFor({waitType: "Appear"}); //Set Destination saveWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: '/Users/nathansalefski/Documents/Pro Tools Sessions',}); //Press Return sf.keyboard.press({ keys: "return"}); //Wait sf.wait({intervalMs: 250}); //Press Return sf.keyboard.press({ keys: "return"}); //Wait sf.wait({intervalMs: 250}); //Wait for Main Window to Appear sf.ui.proTools.mainWindow.elementWaitFor({waitType: "Appear", timeout: -1}) }; //////////////////////////////////////////////////////////////////////////////////////////////// newSessionSetup(); newSessionLoc(); } //////////////////////////////////////////////////////////////////////////////////////////////////// function importIO() { //Define I/O Location const iO = "/Users/nathansalefski/Documents/Pro Tools/IO Settings/NS JUL 2023 MAIN.pio" //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); // Make Reference to IO Window const ioWindow = sf.ui.proTools.windows.whoseTitle.is("I/O Setup").first //Open IO Window sf.ui.proTools.menuClick({ menuPath: ["Setup", "I/O..."], }); //Wait for IO Window to Appear ioWindow.elementWaitFor({waitType: "Appear"}); //Check "Apply to all tabs" Checkbox ioWindow.checkBoxes.whoseTitle.is("Apply to all tabs").first.checkboxSet({ targetValue: "Enable",}); //Click Import Settings ioWindow.buttons.whoseTitle.is("Import Settings...").first.elementClick(); const ioWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Wait for 'Open' Window ioWin.elementWaitFor({waitType: "Appear"}); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for 'Go' Sheet Window to Appear ioWin.sheets.first.elementWaitFor({waitType: "Appear"}); //Set Destination ioWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${iO}`, }); //Press Return sf.keyboard.press({ keys: "return", }); //Wait sf.wait(); //Click Open ioWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for Confirmation Dialog sf.ui.proTools.confirmationDialog.elementWaitFor({waitType: "Appear"}); //Click "Yes" in Confirmation Dialog sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("Yes").first.elementClick(); //Wait for Confirmation Dialog to Disappear sf.ui.proTools.confirmationDialog.elementWaitFor({ waitType: "Disappear", }); //Click "OK" in I/O Window ioWindow.buttons.whoseTitle.is("OK").first.elementClick(); //Wait for I/O Window to Disappear ioWindow.elementWaitFor({ waitType: "Disappear", }); } //////////////////////////////////////////////////////////////////////////////////////////////////// function importSessionData() { //Define Template Location const temp = "/Users/nathansalefski/Documents/Pro Tools Sessions/TEMPLATE/NS JULY 2023 MAIN.ptx" //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Import Session Data sf.ui.proTools.menuClick({ menuPath: ["File","Import","Session Data..."], }); //Define File Window const fileWin = sf.ui.proTools.windows.whoseTitle.is("Open").first; //Wait for 'Open' Window fileWin.elementWaitFor({waitType: "Appear"}); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for 'Go' Sheet Window to Appear fileWin.sheets.first.elementWaitFor({waitType: "Appear"}); //Set Destination fileWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${temp}`, }); //Press Return sf.keyboard.press({ keys: "return", }); //Wait sf.wait(); //Click "Open" fileWin.buttons.whoseTitle.is("Open").first.elementClick(); // Make Reference to Import Session Data Window const iSDWin = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first //Wait for Import Window iSDWin.elementWaitFor({waitType: "Appear"}); //Option Click to Import all Tracks onto New Tracks iSDWin.mouseClickElement({ relativePosition: {"x":185,"y":510}, isOption: true, }); //Click Window Configurations iSDWin.groups.whoseTitle.is("Session Data").first.checkBoxes.whoseTitle.is("Window Configurations").first.checkboxSet({targetValue: 'Enable'}); // Click "Choose..." iSDWin.groups.whoseTitle.is("Session Data").first.buttons.whoseTitle.is("Choose...").first.elementClick(); //Reference Track Data to Import Window const trackData = sf.ui.proTools.windows.whoseTitle.is("Track Data to Import").first //Wait for Track Data Window to Appear trackData.elementWaitFor({waitType: "Appear"}); //Select Import Template from Dropdown Menu trackData.children.whoseRole.is("AXMenuButton").whoseTitle.is("Librarian menu").first.popupMenuSelect({ menuPath: ["Import Template"], }); //Click "OK" in Track Data to Import Window trackData.buttons.whoseTitle.is("OK").first.elementClick(); //Wait for Track Data Window to Disappear trackData.elementWaitFor({waitType: "Disappear"}); //Click "OK" in Import Session Data Window iSDWin.buttons.whoseTitle.is("OK").first.elementClick(); //Wait sf.ui.proTools.waitForNoModals(); } //////////////////////////////////////////////////////////////////////////////////////////////////// function importAudio({ paths }) { //Define Import Audio Window const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Reference to Audio Import Options Window const aIOWin = sf.ui.proTools.windows.whoseTitle.is("Audio Import Options").first paths.forEach(path => { //File, Import, Audio sf.ui.proTools.menuClick({ menuPath: ["File", "Import", "Audio..."], }); //Wait for 'Open' Window openWin.elementWaitFor({ waitType: "Appear" }); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for 'Go' Sheet Window to Appear openWin.sheets.first.elementWaitFor({ waitType: "Appear" }); //Set Destination openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: path }); //Press Return sf.keyboard.press({ keys: "return", }); //Wait for 'Go' Sheet Window to Disappear openWin.sheets.first.elementWaitFor({ waitType: "Disappear" }); //Select All sf.keyboard.press({ keys: "cmd+a", }); //Click "Copy" openWin.buttons.whoseTitle.is("Copy ->").first.elementClick(); //Click "Convert" if (openWin.buttons.whoseTitle.is("Convert ->").first.exists) { openWin.buttons.whoseTitle.is("Convert ->").first.elementClick();} //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for 'Open' Window openWin.elementWaitFor({ waitType: "Appear" }); //Click "Open" openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait for 'Go' Sheet Window to Appear aIOWin.elementWaitFor({ waitType: "Appear" }); //Click "OK" to New Track aIOWin.buttons.whoseTitle.is("OK").first.elementClick(); //Wait sf.ui.proTools.waitForNoModals(); //Move Audio to Folder function moveToFolder() { //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Move Tracks to New Folder sf.ui.proTools.menuClick({ menuPath: ['Track', 'Move to New Folder...'],}); //Define Folder Window const folderWin = sf.ui.proTools.windows.whoseTitle.is("Move To New Folder").first //Wait for Folder Window to Appear folderWin.elementWaitFor({waitType: "Appear"}) //Click Create folderWin.buttons.whoseTitle.is("Create").first.elementClick() //Wait for Folder Window to Disappear folderWin.elementWaitFor({waitType: "Disappear"}) } moveToFolder(); //Deselect All Tracks sf.ui.proTools.trackDeselectAll(); }); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); } //////////////////////////////////////////////////////////////////////////////////////////////////// function main() { //Activate Pro Tools and Refresh Cache sf.ui.proTools.appActivate(); sf.ui.proTools.mainWindow.invalidate(); newSession(); importIO(); importSessionData(); importAudio({ paths: getFolders(trackoutFolder)}); //Save Session sf.ui.proTools.menuClick({ menuPath: ["File", "Save"], }); //Refresh Cache sf.ui.proTools.mainWindow.invalidate(); //Define Session Folder const sessionFolder = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/'); //Move Trackout Folder to Session Folder sf.file.directoryMove({ sourcePath: trackoutFolder, destinationPath: `${sessionFolder}/${trackoutFolderName}` }); } main();