Is there a more elegant/compact way of coding this New Group script?
Title
Is there a more elegant/compact way of coding this New Group script?
What do you expect to happen when you run the script/macro?
This is a New Group script which sets the state of the Attributes page when working non-globally.
Are you seeing an error?
What happens when you run this script?
It works well, but it's slow - I wondered if there's a more elegant way of doing this than just using 60+ set checkbox commands!
How were you running this script?
I used a Stream Deck button
How important is this issue to you?
2
Details
{ "inputExpected": "This is a New Group script which sets the state of the Attributes page when working non-globally.", "inputIsError": false, "inputWhatHappens": "It works well, but it's slow - I wondered if there's a more elegant way of doing this than just using 60+ set checkbox commands!", "inputHowRun": { "key": "-MpfwmPg-2Sb-HxHQAff", "title": "I used a Stream Deck button" }, "inputImportance": 2, "inputTitle": "Is there a more elegant/compact way of coding this New Group script?" }
Source
// Initial script
sf.ui.proTools.appActivateMainWindow();
sf.ui.proTools.groupsEnsureGroupListIsVisible();
sf.ui.proTools.invalidate();
//Type Group Name
var groupName = prompt("Enter Group Name");
// New Group Dialogue
sf.ui.proTools.groupsOpenListPopupMenu().popupMenu.menuClickPopupMenu({ menuPath: ['New Group...'] });
// Wait For Window
sf.ui.proTools.createGroupDialog.elementWaitFor();
//Insert Group Name
sf.keyboard.type({
text: `${groupName}`,
});
// FOLLOW GLOBALS (Enable - Disable)
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is('Follow Globals').first.checkboxSet({
targetValue: "Disable",
});
// GROUP TYPE (Edit - Mix - Edit/Mix)
sf.ui.proTools.createGroupDialog.radioButtons.whoseTitle.is("Mix/Edit").first.elementClick();
// Go To Attributes Tab
sf.ui.proTools.createGroupDialog.radioButtons.whoseTitle.is("Attributes 2 of 3").first.elementClick();
// SET CHECKBOXES (Enable - Disable)
// Volume
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[20].checkboxSet({
targetValue: "Enable",
});
// Mute
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[21].checkboxSet({
targetValue: "Enable",
});
// Pan
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[22].checkboxSet({
targetValue: "Disable",
});
// LFE
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[23].checkboxSet({
targetValue: "Disable",
});
// Controls - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[1].checkboxSet({
targetValue: "Enable",
});
// Controls - B
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[3].checkboxSet({
targetValue: "Enable",
});
// Controls - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[5].checkboxSet({
targetValue: "Enable",
});
// Controls - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[7].checkboxSet({
targetValue: "Enable",
});
// Controls - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[9].checkboxSet({
targetValue: "Enable",
});
// Controls - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[11].checkboxSet({
targetValue: "Enable",
});
// Controls - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[13].checkboxSet({
targetValue: "Enable",
});
// Controls - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[15].checkboxSet({
targetValue: "Enable",
});
// Controls - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[17].checkboxSet({
targetValue: "Enable",
});
// Controls - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[19].checkboxSet({
targetValue: "Enable",
});
// Bypass - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").first.checkboxSet({
targetValue: "Enable",
});
// Bypass - B
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[2].checkboxSet({
targetValue: "Enable",
});
// Bypass - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[4].checkboxSet({
targetValue: "Enable",
});
// Bypass - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[6].checkboxSet({
targetValue: "Enable",
});
// Bypass - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[8].checkboxSet({
targetValue: "Enable",
});
// Bypass - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[10].checkboxSet({
targetValue: "Enable",
});
// Bypass - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[12].checkboxSet({
targetValue: "Enable",
});
// Bypass - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[14].checkboxSet({
targetValue: "Enable",
});
// Bypass - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[16].checkboxSet({
targetValue: "Enable",
});
// Bypass - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[18].checkboxSet({
targetValue: "Enable",
});
// Send Level - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[24].checkboxSet({
targetValue: "Enable",
});
// Send Level - AB
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[28].checkboxSet({
targetValue: "Enable",
});
// Send Level - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[32].checkboxSet({
targetValue: "Enable",
});
// Send Level - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[36].checkboxSet({
targetValue: "Enable",
});
// Send Level - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[40].checkboxSet({
targetValue: "Enable",
});
// Send Level - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[44].checkboxSet({
targetValue: "Enable",
});
// Send Level - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[48].checkboxSet({
targetValue: "Enable",
});
// Send Level - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[52].checkboxSet({
targetValue: "Enable",
});
// Send Level - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[56].checkboxSet({
targetValue: "Enable",
});
// Send Level - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[60].checkboxSet({
targetValue: "Enable",
});
// Send Mute - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[25].checkboxSet({
targetValue: "Enable",
});
// Send Mute - B
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[29].checkboxSet({
targetValue: "Enable",
});
// Send Mute - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[33].checkboxSet({
targetValue: "Enable",
});
// Send Mute - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[37].checkboxSet({
targetValue: "Enable",
});
// Send Mute - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[41].checkboxSet({
targetValue: "Enable",
});
// Send Mute - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[45].checkboxSet({
targetValue: "Enable",
});
// Send Mute - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[49].checkboxSet({
targetValue: "Enable",
});
// Send Mute - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[53].checkboxSet({
targetValue: "Enable",
});
// Send Mute - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[57].checkboxSet({
targetValue: "Enable",
});
// Send Mute - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[61].checkboxSet({
targetValue: "Enable",
});
// Send Pan - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[26].checkboxSet({
targetValue: "Disable",
});
// Send Pan - B
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[30].checkboxSet({
targetValue: "Disable",
});
// Send Pan - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[34].checkboxSet({
targetValue: "Disable",
});
// Send Pan - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[38].checkboxSet({
targetValue: "Disable",
});
// Send Pan - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[42].checkboxSet({
targetValue: "Disable",
});
// Send Pan - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[46].checkboxSet({
targetValue: "Disable",
});
// Send Pan - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[50].checkboxSet({
targetValue: "Disable",
});
// Send Pan - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[54].checkboxSet({
targetValue: "Disable",
});
// Send Pan - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[58].checkboxSet({
targetValue: "Disable",
});
// Send Pan - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[62].checkboxSet({
targetValue: "Disable",
});
// Send LFE - A
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[27].checkboxSet({
targetValue: "Disable",
});
// Send LFE - B
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[31].checkboxSet({
targetValue: "Disable",
});
// Send LFE - C
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[35].checkboxSet({
targetValue: "Disable",
});
// Send LFE - D
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[39].checkboxSet({
targetValue: "Disable",
});
// Send LFE - E
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[43].checkboxSet({
targetValue: "Disable",
});
// Send LFE - F
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[47].checkboxSet({
targetValue: "Disable",
});
// Send LFE - G
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[51].checkboxSet({
targetValue: "Disable",
});
// Send LFE - H
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[55].checkboxSet({
targetValue: "Disable",
});
// Send LFE - I
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[59].checkboxSet({
targetValue: "Disable",
});
// Send LFE - J
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[63].checkboxSet({
targetValue: "Disable",
});
// Record Enable
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("Record Enable").first.checkboxSet({
targetValue: "Enable",
});
// Input Monitoring
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("Input Monitoring").first.checkboxSet({
targetValue: "Enable",
});
// Object Controls
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("Object Controls").first.checkboxSet({
targetValue: "Disable",
});
// Solos
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("Solos").first.checkboxSet({
targetValue: "Enable",
});
// Automation Mode
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("Automation Mode").first.checkboxSet({
targetValue: "Disable",
});
// HEAT Pre/Post
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("HEAT Pre/Post").first.checkboxSet({
targetValue: "Disable",
});
// HEAT Bypass
sf.ui.proTools.createGroupDialog.checkBoxes.whoseTitle.is("HEAT Bypass").first.checkboxSet({
targetValue: "Disable",
});
// Apply Changes and Close
sf.keyboard.press({
keys: "enter",
});
sf.ui.proTools.windows.whoseTitle.is("createGroupDialog").first.elementWaitFor({
waitType: "Disappear",
});
Links
User UID: IPoX41BJQfW8Jfm5DwC4SC8wDo33
Feedback Key: sffeedback:IPoX41BJQfW8Jfm5DwC4SC8wDo33:-OLiw3FNl6prLmwcH-MW
Feedback ZIP: 5zOA44WWeE/XCZl3sE0h0yRO/pK5bgTWRnugBfQe3vsijhcqfrEL31nEKNeJHHDZLsn5GrbycAJ3x2weikVHrjuiAIjfa88iKZDQY1TWAbc0wWtsEb08lbW5wpYvmKkHS6+tX7d5PnfCrLT5KIWlq10ibJgK+j03w9YpcA67VvlFx8Ye5tFaiOgdAOW4LCB3VHsdl6Kr4x7e+uDB1R1DsUKFe1vMG33j5CsuFpj5MI9+5md2Iym8U2c8NYt/f1LBXu/SO4J0yhU/CL2VXpnc8LkRqUpM2LI9qtjb1zm6xiamNZ1iwng8+hpSTnHcbCK4m9BwbqUiMsp+1OxUUG7i26y0TdxtbptRgjO5E+7BTiY=
- Chris Shaw @Chris_Shaw2025-03-19 16:19:49.290Z2025-03-19 16:37:05.759Z
There are two ways to make this much simpler.
Your original script (refactored) will always work:const enableCheckboxNumbers = [20, 21, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61] const enableCheckboxNames = [ 'Record Enable', 'Input Monitoring', 'Solos' ] // Initial script sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.mainWindow.invalidate(); sf.ui.proTools.groupsEnsureGroupListIsVisible(); const createGroupDialog = sf.ui.proTools.createGroupDialog //Type Group Name var groupName = prompt("Enter Group Name"); // New Group Dialogue sf.ui.proTools.groupsOpenListPopupMenu().popupMenu.menuClickPopupMenu({ menuPath: ['New Group...'] }); // Wait For Window createGroupDialog.elementWaitFor(); //Disable all labeled checkboxes createGroupDialog.checkBoxes.invalidate().allItems.forEach(cb => cb.checkboxSet({ targetValue: "Disable", })) // Disable all numbered checkboxes createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").invalidate().allItems.forEach(cb => cb.checkboxSet({ targetValue: "Disable", })) // Name Group createGroupDialog.textFields.first.elementSetTextFieldWithAreaValue({ value: `${groupName}` }); // Enable named checkboxes enableCheckboxNames.forEach(name => { createGroupDialog.checkBoxes.whoseTitle.is(name).first.checkboxSet({ targetValue: "Enable" }) }) // Enable numbered chekcboxes enableCheckboxNumbers.forEach(number => { createGroupDialog.checkBoxes.whoseTitle.is("CheckBox").allItems[number].checkboxSet({ targetValue: "Enable" }) }) createGroupDialog.buttons.whoseTitle.is("OK").first.elementClick() createGroupDialog.elementWaitFor({ waitType: "Disappear", });
Or you can save the group settings using the preset buttons at the bottom of the create group window:
Then you can use this much simpler and faster script:const targetPresetNumber = "1" // Initial script sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.mainWindow.invalidate(); sf.ui.proTools.groupsEnsureGroupListIsVisible(); const createGroupDialog = sf.ui.proTools.createGroupDialog //Type Group Name var groupName = prompt("Enter Group Name"); // New Group Dialogue sf.ui.proTools.groupsOpenListPopupMenu().popupMenu.menuClickPopupMenu({ menuPath: ['New Group...'] }); // Wait For Window createGroupDialog.elementWaitFor(); // Recall group preset createGroupDialog.buttons.whoseTitle.is(targetPresetNumber).first.elementClick(); // Name Group createGroupDialog.textFields.first.elementSetTextFieldWithAreaValue({ value: `${groupName}` }); // Close window createGroupDialog.buttons.whoseTitle.is("OK").first.elementClick() createGroupDialog.elementWaitFor({ waitType: "Disappear", });
The only disadvantage of the second script is that your settings might be different if you use this script on a different system.
Chris Shaw @Chris_Shaw2025-03-19 16:32:12.930Z
Note:
I've noticed you started your script withsf.ui.proTools.invalidate();
.Invalidating PT is rarely necessary and can affect performance when used often. In this script using
sf.ui.proTools.mainWindow.invalidate();
is all that is needed.- TT Francis @T_Francis
Hey Chris,
Thanks for this - I use it as a bit of a default in some scripts because it's been a common was of solving a lot of errors I've seen in a lot in other people's work. Can you explain its actual function and the difference between the two commands?
Chris Shaw @Chris_Shaw2025-03-26 17:35:06.314Z
@chrscheuer has the best explanation of how to correctly use
invalidate()
in this post:
When to use invalidate() #post-2- TT Francis @T_Francis
Fascinating. Thanks for this!