No internet connection
  1. Home
  2. How to

Here's a way to make Stream Decks change dynamically depending on the title of a window.

By Jesper Ankarfeldt @JesperA2019-09-17 05:47:18.717Z2020-05-01 17:06:03.914Z

EDIT: From SF3.6 you can do these dynamic changes straight from the new Title Window SF trigger.

So here's the way to create even more dynamic stream decks. I've made a "walk through" video how to do it, but the quick explanation is that a timer script will change the which deck from SF is being used.

In this example I'm only using window title, but you could also use, window size, or which menus are available.
So for me, I'll also have it change one of my stream deck depending on if I have MIDI or Audio selected, as I have different commands that are specific for those two groups.

Feel free to ask question about the code. Every line that starts with // can be deleted, as they just serve as explanations.

Here's the video:
https://youtu.be/PtCWhsdROLI

Here's the script from the video:

// Set the App ID for the program you want to switch with. 
var app = sf.ui.nuendo

// This starts the timer checking
sf.engine.runInBackground(function () {

    // This creates a variable that is used later 
    var lastFocusedWindowTitle = '';

    // When the loop is running then the following happens. THe loop stops when you no longer have the app in focus: 
    while (true) {

        // This checks for a user cancellation.
        sf.engine.checkForCancellation();

        // This will do so we check every 100 ms if there's been a "change"
        sf.wait({ executionMode: 'Background', intervalMs: 100, onError: 'Continue' });

        // this checks if our front most window is the app we sat in the top of the script. 
        if (sf.ui.frontmostApp.activeBundleID == app.activeBundleID) {

            // This sets a variable of the name of the front most window
            var focusedWindowTitle = sf.ui.frontmostApp.focusedWindow.title.value;

            // If the front most window name has changed we tell the script to do something. 
            //If we don't do this we will get a "chance" every time we loop, so every 100ms. 
            if (focusedWindowTitle !== lastFocusedWindowTitle) {

                // if the front most window contains the text "Direct Offline Processing"
                if (focusedWindowTitle.match('Direct Offline Processing')) {
                    // Input the command id for the deck you want to change to. 
                    sf.soundflow.runCommand({ commandId: 'user:ck0n8ndbf00067z10gdijie0j:ck0n8o2qm000c7z107k36pwic' })
                    sf.soundflow.runCommand({ commandId: 'user:ck0n8ndbf00067z10gdijie0j:ck0navw7j00137z10vjjnewvb' })
                }
                else if (focusedWindowTitle.match('Key Editor')){
                    // Could put another deck in here as well.
                } 
                // in all other cases we get a basic stream deck. 
                else {
                    sf.soundflow.runCommand({ commandId: 'user:cjy8bxtq10002r9101ln8soqf:cjy8byhp60003r9103eecqsxw' })
                    sf.soundflow.runCommand({ commandId: 'user:cjy8bxtq10002r9101ln8soqf:cjybe2r2n0000wp101hwlbahm' })
                }

                // Set the variable lastFocusedWindowTitle to the focues window, for the next loop.
                lastFocusedWindowTitle = focusedWindowTitle;
            }
        }
        // If the app we have in the start is not in focus then we break the loop.
        else
            break;
    }
});
Solved in post #5, click to view
  • 9 replies
  1. Hey Steve. @stevef

    This might be interesting to you as we have talked about something similar.
    With the new deck designer in Soundflow everything is much easier.

    Will also share the packages from the video later when I've tested them a bit more.

    1. In reply toJesperA:

      REALLY COOL! Love this code.

      1. Hey Christian & Jesper,

        I am finally circling back around on this now that I seem to have some time on my hands. I remember that this code needed to be modified to work with Pro Tools. It's beyond me, but would either of you be able to guide me on how to implement that? Seems like an incredibly powerful tool.

        1. I guess we all might get more free time the coming month :/

          I made a small video walkthrough, as I found it hard to explain on text. Let me know if it makes sense.
          https://youtu.be/TtZf4RMxjI0

          Best

          Reply1 LikeSolution
          1. NN Leyers @NickLeyers_old_acc
              2020-03-17 06:41:24.997Z

              Thanks for the video, I'm implementing it allready. Brilliant because now, when I click an audiosuite window, my SD will shows my presets :-) But I guess I'm not going to stop there :-)...

              1. Awesome.

                Hehe, yeah, once you get a taste of it!

                You might experience an error message sometimes, if pro tools is busy so SF can't read the window title name.

                I have yet to figure out the code to implement. I think I know how to do it, but haven't found the time to get to it. Will update you if I do so.

                1. WoW I'm late on this game, once again this is brilliant. I just saw what you're talking about an "error" message that is happens sometimes. I was just messing with the Edit: Mix: and Bounce, and from time to time when I cancel the "Bounce Window" it gives me the errors (something like) focusedWindowTitle is null. I don't know if is the same message that you're seeing in the log, but maybe we can put the "null" into a standard deck or to a display notification message. I'm just thinking out loud! Thanks again. Stay safe

                  1. Yeah, well it's should just have an extra timeout timer for when it can't find a window, which is what happens I think.

                    But if you just use simple windows triggers you should use SF's new window trigger that came in 3.6. It's really amazing.

                    I'm still planing to on using/expanding the script to check for what is selected specifically, so I have different stream decks for when MIDI, Audio, Markers etc is selected.

                    1. As I talked about the other day, I wanted dynamic changes within a window.
                      I've just shared that code here:

                      https://forum.soundflow.org/-2050/dynamic-way-to-change-stream-deck-depending-on-selections-within-a-specific-window