Title
Background function stops working when other scripts are called. (Display different deck on Stream deck by changing the preview mode).
What do you expect to happen when you run the script/macro?
Hi !
This script is supposed to run in the background so other scripts can be called while this one is running. It is supposed to display the deck with the preview button on (that is a script to disable the preview mode) or the deck with the preview button off ( that is a script to enable the preview mode) by looking at the current Preview state.
It is triggered when Pro Tools is active, it cheeks if the 'Edit :' Window is focused, and it is supposed to be up-to-day every 200ms (or any set up ms).
Every thing works, exept the background part because if a call an another script, this one stops running.
Are you seeing an error?
What happens when you run this script?
When Pro Tools is active, the correct deck is displayed. When I change the preview state, the display is updated, the right deck is displayed. When I can another script, that has nothing to do with this one, it works too. But then, this script doesn't work anymore.
How were you running this script?
Other
How important is this issue to you?
3
Details
{ "inputExpected": "Hi !\n\nThis script is supposed to run in the background so other scripts can be called while this one is running. It is supposed to display the deck with the preview button on (that is a script to disable the preview mode) or the deck with the preview button off ( that is a script to enable the preview mode) by looking at the current Preview state.\n\nIt is triggered when Pro Tools is active, it cheeks if the 'Edit :' Window is focused, and it is supposed to be up-to-day every 200ms (or any set up ms).\n\nEvery thing works, exept the background part because if a call an another script, this one stops running.", "inputIsError": false, "inputWhatHappens": "When Pro Tools is active, the correct deck is displayed.\nWhen I change the preview state, the display is updated, the right deck is displayed.\nWhen I can another script, that has nothing to do with this one, it works too.\nBut then, this script doesn't work anymore.", "inputHowRun": { "key": "-MpfwoFyZNOpBC3X5xGI", "title": "Other" }, "inputImportance": 3, "inputTitle": "Background function stops working when other scripts are called. (Display different deck on Stream deck by changing the preview mode)." }
Source
// This function look at the current Preview State and choose the Deck to display on the streamdeck
// It is triggered when Pro Tools is active
function displayDeckWithPreviewState() {
//check if the Edit Window exist. It seems to be the last step made by PT when it launches.
if (sf.ui.proTools.windows.whoseTitle.contains("Edit: ").first.exists) {
// Empty Soundflow cache concerning Pro Tools be to up to date
sf.ui.proTools.invalidate();
// stock preview state
const previewState = sf.ui.proTools.automationWindow.buttons.whoseTitle.is("Enable Auto Preview Mode").first.value.invalidate().value;
//Check if Preview in on
if (previewState === "Selected") {
// Show deck "VERMAAS Preview on"
sf.decks.get('package:cleabq6l50006nb100lsjmmul').showOnStreamDeck({
device: sf.devices.streamDeck.firstDevice,
});
// if preview is off
} else {
// Show deck "VERMAAS Preview off"
sf.decks.get('package:clavi7jie0013xl10hqdmffci').showOnStreamDeck({
device: sf.devices.streamDeck.firstDevice,
});
}
}
}
//////////////
//// MAIN ////
//////////////
sf.ui.proTools.appActivate();
//How often to check in milliseconds
var pollingIntervalMs = 200;
//sf.engine.runInBackground means: Run in background so other commands may run while we're running
sf.engine.runInBackground(function () {
sf.ui.proTools.appWaitForActive();
//while(true) is an endless loop
while (true) {
//Check if anyone requested us to cancel all running commands every time we enter the loop
//The action will take care of aborting this command if necessary
sf.engine.checkForCancellation();
//Here you insert your code you want to execute every 'pollingIntervalMs' ms
displayDeckWithPreviewState();
//Done with this iteration of the loop.
//To not eat up all the CPU, insert a 'wait' here so we wait until next time we want to check
sf.wait({
intervalMs: pollingIntervalMs,
executionMode: 'Background'
});
}
});
Links
User UID: 8SDB1yFJvEO07mZWYsVdB8YZpg62
Feedback Key: sffeedback:8SDB1yFJvEO07mZWYsVdB8YZpg62:-NQFhNrLH-4NhVLiRT10
- Chris Shaw @Chris_Shaw2023-03-11 20:33:34.565Z
You may want to try using this updated version of setting a run forever script:
Select Track as trigger #post-7 - TIn reply toTifanie_Ashba7⬆:Tifanie Ashba @Tifanie_Ashba7
Hello !
It's wonderful thank you, now I'll have to understand it !
Have a nice day !