No internet connection
  1. Home
  2. How to

is there a way to get the currently loaded deck?

By Dustin Harris @Dustin_Harris
    2021-04-03 16:02:05.824Z

    Hi! I want to build a script that will toggle between two decks (neither have 'back' buttons)

    Is there a way to programmatically tell which deck is currently open/displayed?

    sorry for the pseudo-code:

    let currentDeck = "Currently Displayed Deck" //currently displayed deck commandID
    
    let deck_one = "open this deck" //commandID for deck one
    let deck_two = "open that deck" //commandID for deck two
    
    if (currentDeck === deck_one) {
        //..open deck_two
    } else {
        //..open deck_one
    }
    

    Thanks!

    Solved in post #4, click to view
    • 6 replies
    1. A
      Andrew Skipper @Andrew_Skipper
        2021-04-04 21:05:38.257Z

        You can auto switch Deck dependent on window and app open?

        1. Dustin Harris @Dustin_Harris
            2021-04-04 21:26:21.729Z

            Heyya! Thats a great suggestion, but I'm not actually switching any windows for it, I basically want to use two different decks in the same program and switch back and forth between them, and to get the logic to work I need to be able to programmatically tell which deck is the one currently open :) I just don't know how to do that...

          • In reply toDustin_Harris:

            You can get the currentDeckInstance to get a handle to the AxDeckInstance, and then look inside the full instance ID (the command ID of the deck is part of the instance ID):

            log(sf.devices.streamDeck.firstDevice.currentDeckInstance.fullInstanceId);
            
            Reply1 LikeSolution
            1. If you're looking for loaded deck instances on a mobile device, use this:

              sf.devices.mobile.connectedDevices[0]
              

              Edit: Ah, I don't think you actually have access to it through that mechanism.

              1. Also. Remember that if your script is being run by pressing a command on the deck itself, you can just read from event.deck.

                Finally, you could instead opt to store which deck you're showing in a globalState variable that you set in the same script/macro that you use to show the deck. That way you have full control yourself.

                1. Dustin Harris @Dustin_Harris
                    2021-04-04 22:48:44.631Z

                    Oh, that's brilliant! I'd have to work out how to deal with unsynchronized deck / globalState variable, but that is definitely a cool way to approach it!