Trouble with Waiting for Sessions to Finish Loading
Title
Trouble with Waiting for Sessions to Finish Loading
What do you expect to happen when you run the script/macro?
I"m trying to set up a very robust way to "wait for a session to open." This is part of my "bounce in batch" script that still hits errors every once in a while.
Are you seeing an error?
It seems like Pro Tools kind of "goes offline" at certain points while it's loading a session, which causes my "sf.ui.proTools.windows..." commands to break, which gives me some weird errors!
What happens when you run this script?
When I run the script, it works fine, then it usually hits this point where "sf.ui.proTools.windows" becomes undefined, which breaks the script and throws an error. I've tried to "catch" this error using "catch (ex)" to try to keep the script running, but it doesn't always work.
How were you running this script?
I used a keyboard shortcut within the target app
How important is this issue to you?
4
Details
{ "inputExpected": "I\"m trying to set up a very robust way to \"wait for a session to open.\" This is part of my \"bounce in batch\" script that still hits errors every once in a while.", "inputIsError": true, "inputError": "It seems like Pro Tools kind of \"goes offline\" at certain points while it's loading a session, which causes my \"sf.ui.proTools.windows...\" commands to break, which gives me some weird errors!", "inputWhatHappens": "When I run the script, it works fine, then it usually hits this point where \"sf.ui.proTools.windows\" becomes undefined, which breaks the script and throws an error. I've tried to \"catch\" this error using \"catch (ex)\" to try to keep the script running, but it doesn't always work. ", "inputHowRun": { "key": "-Mpfwh4RkPLb2LPwjePT", "title": "I used a keyboard shortcut within the target app" }, "inputImportance": 4, "inputTitle": "Trouble with Waiting for Sessions to Finish Loading" }
Source
try {
while (sf.ui.proTools.invalidate().windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/)).length.valueOf() === 0) {
log('waiting');
sf.wait({ intervalMs: 200 })
};
}
catch (ex) {
log('oops');
sf.wait({ intervalMs: 200 })
while (sf.ui.proTools.invalidate().windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/)).length.valueOf() === null) {
log('really waiting');
sf.wait({ intervalMs: 200 })
}
}
Links
User UID: oMDTMcbKv2OT4GaE3NFzdjMdeXj2
Feedback Key: sffeedback:oMDTMcbKv2OT4GaE3NFzdjMdeXj2:-My0bpOlZwNzMziFL5mW
- Chad Wahlbrink @Chad2022-03-13 05:16:01.077Z
This would be a more "complete version" of what is being run in my "CWPT Bounce In Batch" Script
// Function - Dismiss Dialog (Generic) /** * @param {Object} obj * @param {string} obj.dialogText * @param {string} obj.buttonName */ function dismissDialog({ dialogText, buttonName }) { const dlg = sf.ui.proTools.confirmationDialog; //Wait 100ms for dialog box to appear dlg.elementWaitFor({ timeout: 100, pollingInterval: 10, onError: "Continue", }); if (dlg.children.whoseRole.is("AXStaticText").whoseValue.contains(dialogText).first.exists) { dlg.buttons.whoseTitle.is(buttonName).first.elementClick(); dlg.elementWaitFor({ waitType: "Disappear", timeout: 100, pollingInterval: 10, onError: "Continue", }); } } // Function - Dismiss Missing Files Dialog /** * @param {Object} obj * @param {"Skip All"|"Manually Find & Relink"|"Automatically Find & Relink"} obj.radioButton} */ function dismissMissingFilesDialog({ radioButton }) { const dlg = sf.ui.proTools.windows.whoseTitle.is("Missing Files").first; //Wait for dialog box to appear dlg.elementWaitFor({ timeout: 300, pollingInterval: 10, onError: "Continue", }); if (dlg.exists) { dlg.radioButtons.whoseTitle.is(radioButton).first.elementClick(); dlg.buttons.whoseTitle.is("Ok").first.elementClick(); dlg.elementWaitFor({ waitType: "Disappear", timeout: 100, pollingInterval: 10, onError: "Continue", }); } } // Waiting for a session to finish opening try { while (sf.ui.proTools.invalidate().windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/)).length.valueOf() === 0) { // Ignore Missing I/O if (sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.exists) { sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementClick(); sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" }); } // Ignore Missing Plug-ins if (sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.exists) { sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementClick(); sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" }); } // Dismiss missing files..."" dialog if it appears dismissMissingFilesDialog({ radioButton: "Skip All", }); // Dismiss generic alert if (sf.ui.proTools.windows.whoseDescription.is("alert").first.exists) { sf.ui.proTools.windows.whoseDescription.is("alert").first.getElement("AXDefaultButton").elementClick(); sf.ui.proTools.windows.whoseDescription.is("alert").first.getElement("AXDefaultButton").elementWaitFor({ waitType: "Disappear" }); } sf.wait({ intervalMs: 200 }); } } catch (ex) { sf.wait({ intervalMs: 500 }); log("Waiting"); while (sf.ui.proTools.invalidate().windows.filter(w => w.title.value.match(/^(Edit:|Mix:)/)).length.valueOf() === null) { // Ignore Missing I/O if (sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.exists) { sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementClick(); sf.ui.proTools.windows.whoseTitle.is("Session Notes").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" }); } // Ignore Missing Plug-ins if (sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.exists) { sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementClick(); sf.ui.proTools.windows.whoseTitle.is("Missing AAX Plug-ins").first.buttons.whoseTitle.is("No").first.elementWaitFor({ waitType: "Disappear" }); } // Dismiss missing files..."" dialog if it appears dismissMissingFilesDialog({ radioButton: "Skip All", }); // Dismiss generic alert if (sf.ui.proTools.windows.whoseDescription.is("alert").first.exists) { sf.ui.proTools.windows.whoseDescription.is("alert").first.getElement("AXDefaultButton").elementClick(); sf.ui.proTools.windows.whoseDescription.is("alert").first.getElement("AXDefaultButton").elementWaitFor({ waitType: "Disappear" }); } sf.wait({ intervalMs: 200 }); } } log ("done");
Chad Wahlbrink @Chad2022-03-13 05:16:35.497Z
I find that the script works like 95% of the time right now, but I would love to understand what's happening when the errors are thrown here.
Kitch Membery @Kitch2022-03-14 21:34:04.748Z
Hi @chadwahlbrink,
Ahh, I see. I've had a good result with the following code. This method does not seem to fail when Pro Tools becomes unresponsive. :-)
sf.ui.proTools.appWaitForActive(); sf.ui.proTools.invalidate(); while (sf.ui.proTools.mainWindow.invalidate().sessionPath === null) { sf.engine.checkForCancellation(); // check for dialogs here. sf.wait({ intervalMs: 500 }); } log("Your Pro Tools session has launched.");
Let me know if that works for you :-)