Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

UI escape key returns alert dialog

Engaged ,
Apr 18, 2020 Apr 18, 2020

I am stuck with a problem that I am not sure how to resolve and would like to ask for help from his community.

The Problem: 

Canceling the UI dialog via the escape key on the keyboard and the UI Cancel button returns an alert message.

Screen Shot 2020-04-18 at 1.21.11 PM.png

Screen Shot 2020-04-18 at 1.21.17 PM.png

function dialogTest()
{
// DIALOG
// ======
var dialog = new Window("dialog");
dialog.text = "Script Settings";
dialog.orientation = "row";
dialog.alignChildren = ["left","top"];
dialog.spacing = 10;
dialog.margins = 16;

// GROUP1
// ======
var group1 = dialog.add("group", undefined, {name: "group1"});
group1.orientation = "column";
group1.alignChildren = ["fill","top"];
group1.spacing = 10;
group1.margins = 0;

// PANEL1
// ======
var panel1 = group1.add("panel", undefined, undefined, {name: "panel1"});
panel1.text = "User Settings";
panel1.orientation = "column";
panel1.alignChildren = ["left","top"];
panel1.spacing = 10;
panel1.margins = 15;

var radiobutton1 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton1"});
radiobutton1.text = "User 1";
radiobutton1.value = true;

var radiobutton2 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton2"});
radiobutton2.text = "User 2";

var radiobutton3 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton3"});
radiobutton3.text = "User 3";

var radiobutton4 = panel1.add("radiobutton", undefined, undefined, {name: "radiobutton4"});
radiobutton4.text = "User 4";


var checkbox1 = panel1.add("checkbox", undefined, undefined, {name: "checkbox1"});
checkbox1.text = "Checkbox 1";
checkbox1.alignment = ["left","center"];

// GROUP2
// ======
var group2 = dialog.add("group", undefined, {name: "group2"});
group2.orientation = "column";
group2.alignChildren = ["fill","top"];
group2.spacing = 10;
group2.margins = 0;

var ok = group2.add("button", undefined, undefined, {name: "ok"});
ok.text = "Save";

var cancel = group2.add("button", undefined, undefined, {name: "cancel"});
cancel.text = "Cancel";

dialog.items = {
ok: ok, // button ok
cancel: cancel // button cancel
};
dialog.items.array = [ok, cancel];

dialog.show();

newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);

}

//=============================

dialogTest();

function newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1) {
alert("User 1 = " +radiobutton1.value); return
// alert("User 2 = " +radiobutton2.value);
// alert("User 3 = " +radiobutton3.value);
// alert("User 4 = " +radiobutton4.value);
// alert("Check Box 1 = " +checkbox1.value);
}
TOPICS
Actions and scripting
2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 18, 2020 Apr 18, 2020
if (!(dialog.show() - 1)) newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);
Translate
Adobe
LEGEND ,
Apr 18, 2020 Apr 18, 2020

What different do you expect to happen after canceling (escaping) script if in the code at end is alert?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 18, 2020 Apr 18, 2020

After pressing the escape key or cancel button, the UI dialog should terminate completely.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2020 Apr 18, 2020
if (!(dialog.show() - 1)) newFunction(radiobutton1, radiobutton2, radiobutton3, radiobutton4, checkbox1);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2020 Apr 18, 2020

Yes enter(Save) your default  will terminate the dialog with a return code 1.  Cancel and ESC will terminate the dialog with a return code 2. 

 

In any case the script continue.  If the script loops an additional ESC should cancel the Script but on Windows and Photoshop  it hard to get Photoshop to terminate the running Script.  I do not know if the problem is in Photoshop Plug-in Scriptingsupport or in Photoshop.  I sure Windows would reflect ESC to the running  application Which would be Photoshop or its Plug-in Scriptingsupport.  When a script has an ScruptUI dialog being shown ESC is being reflect to dialog.show and it obliging terminates with a return code 2.   Photoshop scripts do not have ESC event handlers.    So Either Scriptingsupport or Photoshop needs to field the ESC event and terminate the Script some way.

 

Its easy to test to see if dialog show was canceled.  Other dialogs like system dialogs Folder and file section can also be tested.   Script may be able to set up some kind of event handler for ESC.  I do not know for sure.  I know you can set up keyboard handlers that are used within ScriptUI because  I stole Mike Hale code that only allows some keys to be use in dialog numeric files.  Invalid keys are rejected with a beep.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2020 Apr 18, 2020

He explained to me what he'd like to get, not how he wanted, Photoshop behaved.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 18, 2020 Apr 18, 2020

Thank you Kukurykus!, your suggestion works in a mac environment. The alert dialog does not pop up when using the escape key or the cancel button with a custom script. I will test it further in other scripts. Many thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2020 Apr 18, 2020

So why you mark your answer as correct, but not mine? 😛

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2020 Apr 18, 2020

It look like ESC end the Show Dialog.   Your script the preforms your  newfunction that does the alert  so its either true of false depending on which radio button is  checked.   You have set up not cancel test  so enter and cancel do the same thing.  The script ends after you acknowledge the alert.  

 

Esc Cancelled the Dialog not the script.  If fact on windows it often hard to stop a script with ESC or Break.  If a script is in an endless loop I usually  have to kill Photoshop the stop the a script. I doe not know if its a Photoshop problem of a widows problem.  I would think the Photoshop would need to field the ESC and Kill the script. Scripts do not get signal to terminate.  The System or Photoshop would need to terminate the script.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 18, 2020 Apr 18, 2020

Sorry, my mistake. I meant to mark your answer as correct. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 18, 2020 Apr 18, 2020
LATEST

Loll, now you reply outside of subthread, and the answer you marked, was mine indeed, but, not with solution I provided earlier, so I changed it myself eventually 😕

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines