Skip to main content
Known Participant
October 9, 2024
Question

How do we close the dialog box programmatically without click button using extendscript

  • October 9, 2024
  • 2 replies
  • 426 views

Hi Folks,
Is there any possibilities to close dialog box programmatically without click button.

Sample code:

var dlg = new Window('dialog', 'Custom Dialog');
dlg.add('statictext', undefined, 'This is a custom alert!');

var closeBtn = dlg.add('button', undefined, 'Close', {name: 'ok'});
closeBtn.onClick = function() {
dlg.close(); // Programmatically close the dialog
}

dlg.show();
This topic has been closed for replies.

2 replies

m1b
Community Expert
Community Expert
October 9, 2024

A silly example:

var dlg = new Window('dialog', 'Custom Dialog');
dlg.add('statictext', undefined, 'Type "close" to finish!');

var field = dlg.add('edittext {text:"open", alignment:["fill","center"]}');

field.onChanging = function () {
    if ('close' === this.text)
        dlg.close();
}

dlg.show();
Known Participant
October 9, 2024

HI @m1b 
Actually dont touch any button or anything to close modal. It will close after some time like 3 sec or anything.

m1b
Community Expert
Community Expert
October 9, 2024

Ah, I see. I'm pretty sure ScriptUI doesn't allow for anything like that. It only spawns mouse and keyboard events, not time events. Sorry.

m1b
Community Expert
Community Expert
October 9, 2024

Hi @Jothi Sankar Anand S can you give us a bit more idea of what you want to achieve? You sample code already shows how to programmatically close the dialog:

dlg.close();

You don't have to put that in the button's onClick event. You can use it anywhere that you have a valid reference to a visible dialog window.

 

What did you have in mind?

- Mark

Known Participant
October 9, 2024

I'm expecting to close without click event dlg.close(); this one within the onClick event so its not closing automattically like after 3 second

closeBtn.onClick = function() {
dlg.close(); // Programmatically close the dialog
}