Skip to main content
Participating Frequently
November 11, 2025
Question

"Return" will not be captured with Script UI

  • November 11, 2025
  • 3 replies
  • 312 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

While btnCurrent is blue, Space will return "0" and Return will return "1"

0771Author
Participating Frequently
November 11, 2025

@Silly-V  When I test your script I only get a valid Return-key value if i choose "OK" Button with Tab. When I just start the script and press Return, I do not get any resultAction, so it actually does not work, too. It was only missleading because everything is named "OK". ...

 


@Silly-V Name the result variable "NO" than Return key will deliver "NO" while "OK" is preselected actually ... 

function test(){
    var w = new Window("dialog");
    var btn_ok = w.add("button", undefined, "Ok");
    var btn_ok2 = w.add("button", undefined, "Ok-2");
    var resultAction = "NO";
    btn_ok.onActivate = function () {
        resultAction = "Action from Button 'Ok '";
    };
    btn_ok2.onActivate = function () {
        resultAction = "Action from Button 'Ok-2'";
    };
    btn_ok.onClick = function () { w.close(); };
    btn_ok2.onClick = function () { w.close(); };
    w.show();
    alert(resultAction);
};
test();
m1b
Adobe 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
Adobe 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