Saturday, August 25, 2007


ScriptUI Dialog with interacting buttons

Here's a simple script I just banged out to show a simple case of two buttons interacting with each other in a ScriptUI modal dialog:
//DESCRIPTION: Sample Dialog

myDlg = new Window('dialog', 'Example');
myDlg.orientation = 'row';

// Add action buttons
myDlg.btn1 = myDlg.add('button', undefined, 'Disable Him');
myDlg.btn2 = myDlg.add('button', undefined, 'Disable Him');
myDlg.closeBtn = myDlg.add('button', undefined, 'Close');

// Add button functions
myDlg.btn1.onClick = function() {
  if (this.text == 'Disable Him') {
    this.text = 'Enable Him';
    myDlg.btn2.enabled = false;
  } else {
    this.text = 'Disable Him';
    myDlg.btn2.enabled = true;

myDlg.btn2.onClick = function() {
  if (this.text == 'Disable Him') {
    this.text = 'Enable Him';
    myDlg.btn1.enabled = false;
  } else {
    this.text = 'Disable Him';
    myDlg.btn1.enabled = true;

myDlg.closeBtn.onClick = function() {

result =;
if (result == 1) {
  alert("You used the Close button");
Notice that if you close the dialog by hitting the Escape key rather than clicking the Close button, you do not get the alert.

Hi, i try this code and the "function" inside the button didnt run.

is like it dont read my .onclick event.

Did you copy and paste my code or retype it? For instance, it should be .onClick, not .onclick.

I just tried the posted script using InDesign CS4 and ESTK and it worked just as advertised.

I've not tried it with CS5, which I don't have installed on this computer.
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?