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

Is "cancel" a keyword or reserved word in Photoshop?

Engaged ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Is "cancel" a keyword or reserved word?

 

My simple dialog box:

ui.png

 

var dlg = new Window("dialog"); 
    dlg.text = "Proceed?"; 
    dlg.preferredSize.width = 160; 

// GROUP1
// ======
var group1 = dlg.add("group", undefined, {name: "group1"}); 
    group1.preferredSize.width = 160; 

// add buttons
var button1 = group1.add ("button", undefined);
    button1.text = "OK";
var button2 = group1.add ("button", undefined);
    button2.text = "Cancel";


var myReturn = dlg.show();

if (myReturn == 1)
{
   // code here
}

 

 

Works fine. All is well. However replace the string "Cancel" with "Can" and the button no longer functions.

 

can.png

 

 

You need to add extra code in order to regain functionality.

 

button2.onClick = function()
{
  // alert("Byas!");
  dlg.close();
  dialogResponse = "cancel";
}

 

 

So, what's going on, is "cancel" a keyword?

 

TOPICS
Actions and scripting , Windows

Views

207

Translate

Translate

Report

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

Community Expert , May 23, 2022 May 23, 2022

Yes, in ScriptUI – OK and Cancel are "self-defined":

 

From the Bible "Beginning ScriptUI", by Peter Kahrel, page 15:

 


Responding to button presses

The behaviour of buttons other than OK and Cancel must be coded explicitely.

You do this with a so-called callback, in this case onClick. Here is an example:


 

var w = new Window ("dialog");
var e = w.add ("edittext", undefined, "Abcdefg");
var convert_button = w.add ("button", undefined, "Convert to upper case");
w.add ("button", undefined, "OK")
...

Votes

Translate

Translate
Adobe
Community Expert ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Yes, in ScriptUI – OK and Cancel are "self-defined":

 

From the Bible "Beginning ScriptUI", by Peter Kahrel, page 15:

 


Responding to button presses

The behaviour of buttons other than OK and Cancel must be coded explicitely.

You do this with a so-called callback, in this case onClick. Here is an example:


 

var w = new Window ("dialog");
var e = w.add ("edittext", undefined, "Abcdefg");
var convert_button = w.add ("button", undefined, "Convert to upper case");
w.add ("button", undefined, "OK");
convert_button.onClick = function () {e.text = e.text.toUpperCase();}
w.show ();

 

Clicking Convert to upper case converts the text in the edit field to upper

case. This is a simple example, but the functions called by onClick can be of any

complexity. (There are several other types of callback, which we will deal with

later.)

 

Callbacks such as onClick can be combined with other callbacks in one

statement. The following script displays a small panel that we can use to check

the status of the state of the No break attribute.


 

Votes

Translate

Translate

Report

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 ,
May 23, 2022 May 23, 2022

Copy link to clipboard

Copied

Any other "self-defined" or Photoshop only reserved words that may have eluded me?

 

Votes

Translate

Translate

Report

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 ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

LATEST

I don't know, I avoid ScriptUI as much as possible!

 

As for JavaScript/Extendscript, there are of course case sensitive reserved words such as var or function etc.

 

https://www.w3schools.com/js/js_reserved.asp

 

Votes

Translate

Translate

Report

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