Title
How To Create A Folder from inside a dialog box?
What do you expect to happen when you run the script/macro?
If dialog box is open, navigate to current session Bounced Files Folder and create a folder named Stems inside the Bounced Files folder.
Are you seeing an error?
What happens when you run this script?
I have not created the code for Create New Folder and name it Stems yet because I don't know how to write it. This is currently a successful script to get to the current sessions Bounced Files Folder.
How were you running this script?
I used a Stream Deck button
How important is this issue to you?
4
Details
{ "inputExpected": "If dialog box is open, navigate to current session Bounced Files Folder and create a folder named Stems inside the Bounced Files folder.", "inputIsError": false, "inputWhatHappens": "I have not created the code for Create New Folder and name it Stems yet because I don't know how to write it. This is currently a successful script to get to the current sessions Bounced Files Folder.", "inputHowRun": { "key": "-MpfwmPg-2Sb-HxHQAff", "title": "I used a Stream Deck button" }, "inputImportance": 4, "inputTitle": "How To Create A Folder from inside a dialog box?" }
Source
function navigateToInDialog(path) {
//Get a reference to the focused window in the frontmost app:
var win = sf.ui.frontmostApp.focusedWindow;
//Open the Go to... sheet
sf.keyboard.type({ text: '/' });
//Wait for the sheet to appear
var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element;
//It's a combo box on older OS'es, from 12.something it's a text field
if (sheet.comboBoxes.first.exists) {
sheet.comboBoxes.first.value.value = path;
//Press OK
sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"');
}
else {
//Newer OS.
//TextField with AXConfirm
var textField = sheet.textFields.first;
if (!textField.exists) throw `Can't find text field`;
textField.value.value = path;
sheet.elementRaise();
textField.mouseClickElement({
relativePosition: { x: 5, y: 5 },
});
sf.keyboard.press({ keys: 'return' });
}
//Wait for sheet to close
win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 2500 }, '"Go to" sheet didn\'t close in time');
}
var folderPath = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/') + '/Bounced Files';
var currentTitle = sf.ui.frontmostApp.focusedWindow.title.value;
if (!currentTitle || currentTitle.match(/open|import|save/i)) {
navigateToInDialog(folderPath);
} else {
sf.system.exec({ commandLine: 'open "' + folderPath + '"' });
sf.ui.finder.appActivateMainWindow();
sf.ui.finder.windows.first.elementRaise();
}
Links
User UID: I7doJ14mp3dUHDwLh8NxCBcVqcK2
Feedback Key: sffeedback:I7doJ14mp3dUHDwLh8NxCBcVqcK2:-O47qLj8WrqlxUTeBazQ
Feedback ZIP: zG1wKQcqAoKn8vbaSh24EWN2lMVSrOlxJp2vyw06SajkiY6CM8k/k/0l9fkDXPFbPUSRHgvcxzuVcc3QjGZPsYKplzpToeXU6G9Hkog2KJpBUM9hz1QkSj9X591xYQ+CJx5otrmWZzwUtTItr/pMfXB2hF8vMaoeolp99yms1p86yhAxBTXtCGisNp765Sn8sl/MAqodTVhMk1AXBaBqGMAlNXk0d+PVqUUiQHkA8sjFPkr+dVFTOdAB1HhQmYIfw+uBzKO2jZZk2siXW+Z3pAGnmwzKTBafQTV8CsiZhgaFQjAEowaME3pifd3GqIE+T6UjaoQDhX780amtyckC/w==
- BBrandon Jiaconia @Brandon_Jiaconia
quoted text
This snippet is what I use for something similar. You'll need to incorporate it into the rest of what you're trying to accomplish, and change the name of the stems to what you need them to be.
function navigateToInDialog(path) { //Get a reference to the focused window in the frontmost app: var win = sf.ui.frontmostApp.focusedWindow; //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //It's a combo box on older OS'es, from 12.something it's a text field if (sheet.comboBoxes.first.exists) { sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); } else { //Newer OS. //TextField with AXConfirm var textField = sheet.textFields.first; if (!textField.exists) throw `Can't find text field`; textField.value.value = path; sheet.elementRaise(); textField.mouseClickElement({ relativePosition: { x: 5, y: 5 }, }); sf.keyboard.press({ keys: 'return' }); } //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 2500 }, '"Go to" sheet didn\'t close in time'); } var folderPath = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/') + '/Bounced Files' navigateToInDialog(folderPath); // Navigate and relabel files const labels = ["Stem_01", "Stem_02", "Stem_03"]; labels.forEach(label => { sf.keyboard.press({ keys: "cmd+shift+n" }); sf.wait({ intervalMs: 250 }); sf.keyboard.type({ text: label }); sf.keyboard.press({ keys: "return" }); var folderPath = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/') + '/Bounced Files' navigateToInDialog(folderPath); sf.wait({ intervalMs: 250 }); });
John Costello @John_Costello
Hello Brandon!
I just love this! I have mad respect for your work in sound design!
I modified your script by taking out 2 of the stem labels. Doing this creates a single folder, works fine. Is there a way to modify your script to move into that single folder and hit enter? This would be as if using the "export clip as file" option in the clips bin to create selected clips as "stems" into a single folder. No rush...
Thank you so much for helping me!
JC3 Media Music
- BBrandon Jiaconia @Brandon_Jiaconia
Hey John - I think this works the way you are asking.
function navigateToInDialog(path) { //Get a reference to the focused window in the frontmost app: var win = sf.ui.frontmostApp.focusedWindow; //Open the Go to... sheet sf.keyboard.type({ text: '/' }); //Wait for the sheet to appear var sheet = win.sheets.first.elementWaitFor({ timeout: 500 }, 'Could not find "Go to" sheet in the Save/Open dialog').element; //It's a combo box on older OS'es, from 12.something it's a text field if (sheet.comboBoxes.first.exists) { sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); } else { //Newer OS. //TextField with AXConfirm var textField = sheet.textFields.first; if (!textField.exists) throw `Can't find text field`; textField.value.value = path; sheet.elementRaise(); textField.mouseClickElement({ relativePosition: { x: 5, y: 5 }, }); sf.keyboard.press({ keys: 'return' }); } //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 2500 }, '"Go to" sheet didn\'t close in time'); } var folderPath = sf.ui.proTools.mainWindow.sessionPath.split('/').slice(0, -1).join('/') + '/Bounced Files' navigateToInDialog(folderPath); // Navigate and relabel files const labels = ["Stem_01"]; labels.forEach(label => { sf.keyboard.press({ keys: "cmd+shift+n" }); sf.wait({ intervalMs: 250 }); sf.keyboard.type({ text: label }); sf.wait({ intervalMs: 250 }); sf.keyboard.press({ keys: "return", repetitions: 4, fast: false }); sf.wait({ intervalMs: 250 }); });
There is definitely a more professional way to do this, I just dont know how.
John Costello @John_Costello
Hi Brandon!
Works like a charm!
I modified the end of your script with an extra Return command. This fully executes the Export Clips command (After typing "Ok" and hitting Return inside the dialog box, which dismisses it). Perfecto! Now I have the option to tack this onto other scripts I have that utilize the Export Clips command.
Thank you so much for helping me!
JC3
The more ways to skin a cat the better! If you like skinning cats..