Title
Check Folder for Audio Files: If They Exists, Import Them
What do you expect to happen when you run the script/macro?
Session Prep Script
Are you seeing an error?
What happens when you run this script?
It works as expected. I want to add functionality described in the comment below
How were you running this script?
I used a Stream Deck button
How important is this issue to you?
5
Details
{
"inputExpected": "Session Prep Script",
"inputIsError": false,
"inputWhatHappens": "This will set up a session, importing Audio, I/O and my Template. It will gather the pathways of subfolders within a main folder and import the audio from each. I would like to have it check the main folder for audio as well",
"inputHowRun": {
"key": "-MpfwmPg-2Sb-HxHQAff",
"title": "I used a Stream Deck button"
},
"inputImportance": 5,
"inputTitle": "Import Audio from a Folder and it's Subfolders"
}
Source
function getFolders(path) { return sf.file.directoryGetDirectories({ path, isRecursive: true, }).paths}
function importAudioForEach({ 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", });
//Try "Copy" or "Convert"
try {openWin.buttons.whoseTitle.is("Copy ->").first.elementClick();}
catch(err) {
sf.wait({intervalMs: 200});
if (openWin.buttons.whoseTitle.is("Convert ->").first.exists) {
try {openWin.buttons.whoseTitle.is("Convert ->").first.elementClick();}
catch(err) {log('Could Not Import Audio')};
} else {log('Could Not Import Audio'); throw 0;}
}
//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();
}
importAudio({ paths: getFolders(selectedFolder) });
Links
User UID: EoVu20w2ZRTvmJvgozc57ZXuAhU2
Feedback Key: sffeedback:EoVu20w2ZRTvmJvgozc57ZXuAhU2:-Ncdqg5q_o1dBefG1PGg
Nathan Salefski @nathansalefskiCurrently it will import all of the audio depicted below except "MAIN FOLDER 1" and "MAIN FOLDER 2". I know
importAudio({ paths: getFolders(selectedFolder) });is only getting the pathways of folders within the selected folder and that is why, but I would like to be able to check for audio files within the main folder. If it exists, import it along with the other files.
Nathan Salefski @nathansalefskiI think I got it. Just need an additional function for importing from this path. Could someone confirm?
function checkForWAVE(path) {return sf.file.directoryGetFiles({searchPattern: "*" + '.wav', path: path }).paths[0]} function checkForMP3(path) {return sf.file.directoryGetFiles({searchPattern: "*" + '.mp3', path: path }).paths[0]} const wav = checkForWAVE(selectedFolder); const mp3 = checkForMP3(selectedFolder); if (wav || mp3) { importAudio({ path: selectedFolder }) };