Reset button state in ScriptUI

AiScripts
2 min readNov 11, 2021

--

In ScriptUI dialogs, when you click on a button, the status of button.active changes from false to true. The problem occurs when you need to reset the focus (highlighting) of a button or other element: checkbox, text box, etc. This can be seen when the buttons in the dialog are used as switchers.

When you press the button again, the blue highlight remains

The onClick event with a status change can be triggered with one button or another element.

button.onClick = function () {
// do something..
button.active = !button.active;
}

Solution

After clicking the button is active, to reset the state you need to force true on the active attribute and then force false on it again in the script code for the onClick event. I used this solution in SelectPointsByType in a loop that follows the onClick event for buttons that are grouped together.

var btns = dialog.add('group'); 
// ...
for (var i = 0; i < btns.children.length; i++) {
btns.children[i].onClick = function () {
// do something..
// Reset button highlight
this.active = true;
this.active = false;
}
}
Blue highlight fixed, and the user will not see the temporary checkbox

--

--

AiScripts
AiScripts

Written by AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts

No responses yet