No internet connection
  1. Home
  2. How to

Remove Track from 1 group

By Jack Green @Jack_Green
    2024-02-23 15:34:43.280Z

    Hi,

    Looking to be able to remove a track from 1 group. but leave it to all other groups it may be assigned too.

    I have a way I could do it but it feels super convoluted/dirty. Build an array of all the tracks that are in the group that are not the track I want to remove than use the replace function within the group window.

    figured I would ask if anyone had a better way before I do it that way?

    Thanks in advance !

    Jack

    Solved in post #2, click to view
    • 5 replies
    1. Nathan Salefski @nathansalefski
        2024-02-23 19:16:44.611Z2024-02-23 20:53:49.693Z

        Try this. You'll just have to ensure every group you have is visible in group list. I haven't found a work around for that yet:

        function getGroupRows() {
            let editWindowMenuItem = sf.ui.proTools.getMenuItem('Window', 'Edit');
            let mixWindowMenuItem = sf.ui.proTools.getMenuItem('Window', 'Mix');
        
            if (editWindowMenuItem.isMenuChecked) {
                let groupRows = sf.ui.proTools.mainWindow.invalidate().groupListView.childrenByRole('AXRow');
        
                return groupRows;
            } else if (mixWindowMenuItem.isMenuChecked) {
                let groupRows = sf.ui.proTools.mixWindow.invalidate().tables.whoseTitle.is("Group List").first.childrenByRole('AXRow');
        
                return groupRows;
            }
        }
        
        function matchGroupsToSelection(groupRows) {
            sf.ui.proTools.groupsEnsureGroupListIsVisible();
        
            let groupsContainingSelectedTrack;
        
            const targetGroupRow = groupRows.map(r => ({
                groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                btn: r.childrenByRole('AXCell').first.buttons.first.value.invalidate().value,
            })).filter(g => g.btn == 'Track selection partially contains group');
        
            if (targetGroupRow) {
                groupsContainingSelectedTrack = targetGroupRow.map(row => row.groupName);
            }
        
            return groupsContainingSelectedTrack
        }
        
        function selectTracksInGroup(groupName, groupRows) {
            sf.ui.proTools.groupsEnsureGroupListIsVisible();
        
            const targetGroupRow = groupRows.map(r => ({
                groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                btn: r.childrenByRole('AXCell').allItems[1].buttons.first,
            })).filter(g => g.groupName === groupName)[0]
        
            targetGroupRow.btn.popupMenuSelect({
                isRightClick: true,
                menuPath: ['Select Tracks In Group'],
            }, `Group Not Visible`);
        }
        
        function modifyTracksInGroup(groupName, groupRows) {
            sf.ui.proTools.groupsEnsureGroupListIsVisible();
        
            const targetGroupRow = groupRows.map(r => ({
                groupName: r.childrenByRole('AXCell').allItems[1].buttons.first.title.value.split(/-\s/)[1],
                btn: r.childrenByRole('AXCell').allItems[1].buttons.first,
            })).filter(g => g.groupName === groupName)[0]
        
            targetGroupRow.btn.popupMenuSelect({
                isRightClick: true,
                menuPath: ['Modify...'],
            }, `Group Not Visible`);
        
            const modifyGroupWin = sf.ui.proTools.windows.whoseTitle.is("Modify Groups").first;
        
            modifyGroupWin.elementWaitFor();
        
            modifyGroupWin.buttons.whoseTitle.is("Replace").first.elementClick();
        
            modifyGroupWin.buttons.whoseTitle.is("OK").first.elementClick();
        
            modifyGroupWin.elementWaitFor({ waitType: "Disappear" });
        }
        
        function main() {
            sf.ui.proTools.appActivateMainWindow();
            sf.ui.proTools.mainWindow.invalidate();
        
            let groupRows = getGroupRows();
        
            let nameOfTrackToRemove = sf.ui.proTools.invalidate().selectedTrackNames[0];
        
            let groupsContainingTrackToRemove = matchGroupsToSelection(groupRows).filter(gn => { return gn !== '<ALL>' });
        
            let removalGroup = sf.interaction.selectFromList({
                title: 'Remove Track from Group',
                prompt: `Please select which Group you'd like to remove the Track from`,
                items: groupsContainingTrackToRemove,
                oKButton: 'Confirm Group',
                cancelButton: 'Cancel'
            }).list[0];
        
            selectTracksInGroup(removalGroup, groupRows);
        
            let selectedTracksInGroup = sf.ui.proTools.invalidate().selectedTrackNames;
        
            sf.ui.proTools.trackSelectByName({
                names: selectedTracksInGroup.filter(tn => { return tn !== nameOfTrackToRemove }),
                deselectOthers: true,
            });
        
            modifyTracksInGroup(removalGroup, groupRows);
        
            alert(`${nameOfTrackToRemove} removed from ${removalGroup}`)
        }
        
        main();
        
        Reply1 LikeSolution
        1. Jack Green @Jack_Green
            2024-02-27 10:59:51.318Z

            This works brilliantly thank you!

            1. In reply tonathansalefski:
              Nathan Salefski @nathansalefski
                2024-02-27 14:20:26.374Z

                @chrscheuer any ideas on how to have scroll to the group given its not visible?

                1. I don't think I ever made scrolling work well for this, although that doesn't mean it would be impossible to build. Unfortunately, I don't have time to look into it right now, but the steps would be something like:

                  • Check if the group list item's frame is contained within the table's frame (meaning, it's visible)
                  • If it's not, simulate a mouse scroll event over the table
                  • Repeat the check from step 1, and then repeat step 2 until the item is in fact visible
              • J
                In reply toJack_Green:
                Jacob Bauman @Jacob_Bauman
                  2025-03-10 18:15:23.452Z

                  Can the script be adjusted to allow users to select one or more tracks and unassign them from all current groups?