No internet connection
  1. Home
  2. How to

Checking if the group is active or not

By Samuel Škubla @Samuel_Skubla
    2020-10-15 10:23:01.656Z

    Hello,

    Is there any way to check if defined group is active or not?

    Thank you!

    Solved in post #3, click to view
    • 13 replies
    1. Spun off from this:

      1. In reply toSamuel_Skubla:

        This should work :)

        
        function isGroupActive(groupName) {
            let grp = sf.ui.proTools.mainWindow.groupListView.childrenByRole('AXRow').map(r => {
                let btn = r.childrenByRole('AXCell').allItems[1].buttons.first;
                return {
                    groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                    btn,
                    isActive: btn.title.invalidate().value.indexOf('Active ') === 0,
                    row: r,
                };
            }).filter(g => g.groupName === groupName)[0];
            if (!grp) throw `Group with name "${groupName}" was not found`;
            return grp.isActive;
        }
        
        if (isGroupActive("Group 2")) {
            log('Yes');
        } else {
            log('No');
        }
        
        Reply1 LikeSolution
        1. Note, this could also be augmented to a "setGroupActive" function where you specify exactly the desired state instead of toggling:

          
          /**
           * @param {string} groupName
           * @param {boolean} targetValue Set to true (active) or false (inactive)
           */
          function setGroupActive(groupName, targetValue) {
              let grp = sf.ui.proTools.mainWindow.groupListView.childrenByRole('AXRow').map(r => {
                  let btn = r.childrenByRole('AXCell').allItems[1].buttons.first;
                  return {
                      groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                      btn,
                      isActive: btn.title.invalidate().value.indexOf('Active ') === 0,
                      row: r,
                  };
              }).filter(g => g.groupName === groupName)[0];
              if (!grp) throw `Group with name "${groupName}" was not found`;
              if (grp.isActive !== !!targetValue)
                  grp.btn.elementClick();
          }
          
          setGroupActive("Group 2", true);
          
        2. In reply toSamuel_Skubla:
          Erik Griekspoor @Erik_Griekspoor
            2020-10-19 08:39:17.609Z

            So what does this do? Would be fantastic if you could see on the toggle button on your streamdeck if a group is actived or not.

            1. Erik Griekspoor @Erik_Griekspoor
                2020-10-19 08:49:53.425Z

                Ah I see now how it works, this is already great, The only disadvantage is that you need two buttons now instead of one. Is it possible to highlight a button on the streamdeck when it is activated?

                1. Samuel Škubla @Samuel_Skubla
                    2020-10-19 09:08:00.298Z

                    This should work.

                    
                    /*
                     * @param {string} groupName
                     */
                    function setGroupActive(groupName) {
                        let grp = sf.ui.proTools.mainWindow.groupListView.childrenByRole('AXRow').map(r => {
                            let btn = r.childrenByRole('AXCell').allItems[1].buttons.first;
                            return {
                                groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                                btn,
                                isActive: btn.title.invalidate().value.indexOf('Active ') === 0,
                                row: r,
                            };
                        }).filter(g => g.groupName === groupName)[0];
                        if (!grp) throw `Group with name "${groupName}" was not found`;
                        grp.btn.elementClick();
                    }
                    
                    setGroupActive("Group 2");
                    
                    1. Erik Griekspoor @Erik_Griekspoor
                        2020-10-19 09:54:51.331Z

                        Thanks! It does toggle the Group but I dont see something changing on my streamdeck button though, should I have a certain color icon or something?

                        1. Samuel Škubla @Samuel_Skubla
                            2020-10-19 10:06:22.184Z

                            I think this is currently not possible by easy way, but I know there is a way to change icons from script. Maybe someone could give us a hand with this one.

                            1. Erik Griekspoor @Erik_Griekspoor
                                2020-10-19 12:47:05.780Z

                                That would be awesome..

                      • In reply toSamuel_Skubla:
                        Erik Griekspoor @Erik_Griekspoor
                          2021-04-01 07:52:23.369Z

                          These scripts somehow dont work anymore, could somebody look in to this?
                          Also I'm still very interested in the Icon on the streamdeck changing when a group is activated or not..

                          1. In reply toSamuel_Skubla:
                            Erik Griekspoor @Erik_Griekspoor
                              2021-04-01 07:57:59.782Z

                              I get the notification:
                              Group with name "V_FX_A" was not found
                              (Toggle Group V_FX_A line 11)

                              The name of the group is exactly the some though..

                              1. In reply toSamuel_Skubla:
                                Erik Griekspoor @Erik_Griekspoor
                                  2021-04-01 08:07:12.071Z

                                  Aha, I found out its because a VCA is assigned to the group.
                                  How can I make this script work with VCA's asigned to the group?

                                  function toggleGroupActive(groupName) {
                                  sf.ui.proTools.mainWindow.groupListView.childrenByRole('AXRow').map(r => ({
                                  groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                                  btn: r.childrenByRole('AXCell').allItems[1].buttons.first,
                                  row: r,
                                  })).filter(g => g.groupName === groupName)[0].btn.elementClick();
                                  }

                                  toggleGroupActive("Group 2");

                                  1. In reply toSamuel_Skubla:
                                    Erik Griekspoor @Erik_Griekspoor
                                      2021-04-01 08:12:32.501Z

                                      Ah, I found out that if you add the (VCANAME) to the groupname it works!