Hello,
I have the following script to import an AAF, but would like the option for the script to be aborted when I cancel out of this first "open file" window..:

When I manually cancel this window (either with esc-key or by clicking "cancel"), the script keeps continuing, and I don't want that.
How do I do that?
Here's the script:
sf.ui.proTools.appActivate();
sf.ui.proTools.appWaitForActive();
sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Main Counter").first.elementClick();
sf.keyboard.press({ keys: "cmd+c, return", });
sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] });
sf.ui.proTools.windows.whoseTitle.is("Open").first.getElement("AXDefaultButton").elementWaitFor({
onCancel: "Abort",
onError: "Continue",
});
var dlg = sf.ui.proTools.dialogWaitForManual({
dialogTitle: 'Import Session Data',
timeout: -1
}).dialog;
var popupBtn = dlg.groups.getByTitle('Media Options').popupButtons.allItems[1];
popupBtn.popupMenuSelect({
menuPath: ['Copy from source media']
});
Thanks!
Linked from:
- Chris Shaw @Chris_Shaw2022-06-29 17:08:07.381Z2022-06-29 17:55:44.187Z
Hey AL_L,
As far as I know there's no way for SF to know which button has been clicked in the Open File dialog but we can tell when windows and dialogs appear and disappear so we can use that info to get the results you want.
The key here is to wait and see if the Import Session Data window appears after the Open File dialog disappears. If it doesn't then the user must have clicked cancel in the Open File dialog:
sf.ui.proTools.appActivate(); sf.ui.proTools.appWaitForActive(); sf.ui.proTools.mainWindow.counterDisplay.textFields.whoseTitle.is("Main Counter").first.elementClick(); sf.keyboard.press({ keys: "cmd+c, return", }); sf.ui.proTools.menuClick({ menuPath: ['File', 'Import', 'Session Data...'] }); //Wait for Open Session window to appear sf.ui.proTools.windows.whoseTitle.is("Open").first.elementWaitFor({ }); // Wait for open session window to disappear sf.ui.proTools.windows.whoseTitle.is("Open").first.elementWaitFor({ waitType: "Disappear", timeout: -1 }); // Now that the open files window is gone // Briefly wait for any confirmation dialogs that may appear before Import Track Data window (If the user clicked "Open") // (ex: "Session Start Time is different" ) const confWin = sf.ui.proTools.confirmationDialog const isThereAConfWin = confWin.elementWaitFor({ timeout: 500, onError: "Continue" }).success // If there is a confirmation window, wait for the user to dismiss it if (isThereAConfWin){ confWin.elementWaitFor({waitType:"Disappear",timeout:-1}) } // Now let's wait for the Import Session Data window to appear. If it doesn't then user must have canceled // We'll store the results by using the `.success` property const didImportWindowAppear = sf.ui.proTools.windows.whoseTitle.is("Import Session Data").first.elementWaitFor({ timeout: 500, pollingInterval: 100, onError: "Continue" }).success //success will return true or false //If Import Session Data window did not appear, stop the script if (!didImportWindowAppear) { sf.interaction.notify({ title: "User Canceled" }); throw 0 } // If we're here the then the Import Session Data window must be open. // Continue on - var dlg = sf.ui.proTools.dialogWaitForManual({ dialogTitle: 'Import Session Data', timeout: -1 }).dialog; var popupBtn = dlg.groups.getByTitle('Media Options').popupButtons.allItems[1]; popupBtn.popupMenuSelect({ menuPath: ['Copy from source media'] });
- AIn reply toAL_L⬆:AL L @AL_L
@Chris_Shaw Thanks so much ! That worked perfectly...