Skip to main content
Known Participant
Oct 9, 2024 11:19 AM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

6 replies

m1b
Community Expert
Community Expert
Oct 9, 2024 11:36 AM UTC

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();
Translate
Known Participant
Oct 9, 2024 11:43 AM UTC

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

Translate
m1b
Community Expert
Community Expert
Oct 9, 2024 11:26 PM UTC

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.

Translate
m1b
Community Expert
Community Expert
Oct 9, 2024 11:32 AM UTC

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

Translate
Known Participant
Oct 9, 2024 11:37 AM UTC

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
}
Translate