shortcut to take selected file in finder..drag into protools
How would I automate having my selected audio file in a finder window import into ProTools, creating a new audio track with that name, spot to the start of the session? Basically simulating dragging a file from the finder to the protools window.
- Christian Scheuer @chrscheuer2020-05-05 17:28:28.933Z
Hi Jonathan
Simulating mouse dragging is usually not the best option, since it can be very brittle (for example if the user moves the mouse, or if other windows overlay etc..)
A better way to achieve this, would be to automate using the Import Audio workflow for this.
- JJonathan Grossman @Jonathan_Grossman
Here's where I am...for some reason the ProTools import audio box is no the focues window so the macro can't click on the UI element. Getting an error...screen shot below.
var myFilePath = sf.appleScript.finder.firstWindow.targetPath;
sf.ui.proTools.appActivate();
sf.ui.proTools.menuClick({
menuPath: ["File","Import","Audio..."],
});sf.ui.proTools.windows.whoseTitle.is('Open').first.textFields.first.elementClick();
Christian Scheuer @chrscheuer2020-05-06 17:19:14.487Z
You should have an action that waits for the window to appear, before trying to act on anything inside the window:
sf.ui.proTools.windows.whoseTitle.is('Open').first.elementWaitFor();
I also walk through that technique in the videos I sent you :)
In terms of the elementClick on the text field, then you may instead want to use the "Set Value of Text Field in Text Area" action, or use a complete function for navigating to the correct file - there are examples of this script in the "Navigate to Folder of Current Session" functions in the Pro Tools Utilities package, check it here:
function navigateToInOpenDialog(path) { //Get a reference to the focused window in the frontmost app: var win = sf.ui.proTools.windows.whoseTitle.is('Open').first; //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; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); }
To string it together:
function navigateToInOpenDialog(path) { //Get a reference to the focused window in the frontmost app: var win = sf.ui.proTools.windows.whoseTitle.is('Open').first; //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; //Set the value of the combo box sheet.comboBoxes.first.value.value = path; //Press OK sheet.buttons.whoseTitle.is('Go').first.elementClick({}, 'Could not click "Go"'); //Wait for sheet to close win.sheets.first.elementWaitFor({ waitForNoElement: true, timeout: 500 }, '"Go to" sheet didn\'t close in time'); } var myFilePath = sf.appleScript.finder.firstWindow.targetPath; sf.ui.proTools.appActivate(); sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], }); sf.ui.proTools.windows.whoseTitle.is('Open').first.elementWaitFor(); navigateToInOpenDialog(myFilePath);
- JJonathan Grossman @Jonathan_Grossman
Thanks! Will watch those videos as well before I email again. :-)