Skip to main content
Participating Frequently
November 11, 2025
Question

"Return" will not be captured with Script UI

  • November 11, 2025
  • 3 replies
  • 426 views

Thsi Script exports PDF files to a given folder without saving the current AI-file.

When one of the dialoge windows is open, I can navigate through the options and choose them with space-key. So the button gets blue higlighted but the predefined keeps its white outline. But hitting "Return" an the blue colored button, will not work at all. It will activate the white outlined button.
Space will activate the blue higlighted instead, like one would expect it from "Retrun", too.

Any idea how to capture "Return" when choosing e.g. "Abbrechen" in this dialogue?

function askDocumentChoice() {
    var dlg = new Window("dialog", "Welche Dokumente speichern?");

    dlg.add("Group {orientation:'row', alignment:['fill','top']}").add("statictext", undefined, "Sollen alle geöffneten Dokumente gespeichert werden?");
    dlg.add("Group {orientation:'row', alignment:['fill','top']}").add("statictext", undefined, "(oder nur das aktuelle?)");

    var buttonRow = dlg.add("Group {orientation:'row', alignment:['right','top']}");

    var btnCurrent = buttonRow.add("button", undefined, "Nur aktuelles");
    var btnAll = buttonRow.add("button", undefined, "Alle", { name: 'ok' });
    var btnCancel = buttonRow.add("button", undefined, "Abbrechen", { name: 'cancel' });

    btnCurrent.onClick = function() { dlg.close(0); };
    btnAll.onClick = function() { dlg.close(1); };
    btnCancel.onClick = function() { dlg.close(-1); };

    dlg.defaultElement = btnAll;
    dlg.cancelElement = btnCancel;

    dlg.center();
    return dlg;
}

3 replies

RobOctopus
Inspiring
November 11, 2025

I don't see your dlg.show() line anywhere, but writing it to say "return dlg.show()" will return the number values passed through the .close() method.

function askDocumentChoice() {
    var dlg = new Window("dialog", "Welche Dokumente speichern?");

    dlg.add("Group {orientation:'row', alignment:['fill','top']}").add("statictext", undefined, "Sollen alle geöffneten Dokumente gespeichert werden?");
    dlg.add("Group {orientation:'row', alignment:['fill','top']}").add("statictext", undefined, "(oder nur das aktuelle?)");

    var buttonRow = dlg.add("Group {orientation:'row', alignment:['right','top']}");

    var btnCurrent = buttonRow.add("button", undefined, "Nur aktuelles");
    var btnAll = buttonRow.add("button", undefined, "Alle", { name: 'ok' });
    var btnCancel = buttonRow.add("button", undefined, "Abbrechen", { name: 'cancel' });

    btnCurrent.onClick = function() { return dlg.close(0); };
    btnAll.onClick = function() { return dlg.close(1); };
    btnCancel.onClick = function() { return dlg.close(4); };

    dlg.defaultElement = btnAll;
    dlg.cancelElement = btnCancel;

    return dlg.show()
}

alert(askDocumentChoice())
0771Author
Participating Frequently
November 11, 2025

@RobOctopus the script works fine it's all about the Return trigger here. I would expect Return to trigger the same as Space key. But it seems this is not the case...

RobOctopus
Inspiring
November 11, 2025

ahh I had misunderstood. disregard my comment then!

m1b
Community Expert
Community Expert
November 11, 2025

Hi @0771 the Return key will trigger the onClick handler for the button whose `name` === "ok".

Similarly, the Escape key will trigger the button named "cancel".

 

Does that answer your question or have I misunderstood the point?

-Mark

0771Author
Participating Frequently
November 11, 2025

@m1b so while Space key can trigger all, Return will always and only capture "ok"? 

m1b
Community Expert
Community Expert
November 11, 2025

Yes return will trigger "ok" button. Space will trigger the active control. 

0771Author
Participating Frequently
November 11, 2025

Sorry for the wrong grammatic, but I cannot edit my post anymore... So I just wanted to add I navigate with Tab-key through the different buttons.

0771Author
Participating Frequently
November 11, 2025