You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Photoshop脚本开发疑问:“cancel”是否为关键字或保留字?

Why does changing the Cancel button text break its default functionality in Photoshop scripting?

Great question! Let's break down what's happening here:

The core reason

Photoshop's ExtendScript dialog system (using the Window("dialog") class) has built-in logic for standard button text values. When you set a button's text to one of these predefined strings—like "OK", "Cancel", "Yes", or "No"—the system automatically attaches default behavior to the button:

  • A button labeled "OK" will automatically close the dialog and make dlg.show() return 1
  • A button labeled "Cancel" will automatically close the dialog and make dlg.show() return 2

When you change the button text to "Can", it's no longer recognized as a standard cancel button. The system doesn't apply that default close/return logic anymore, which is why the button stops working unless you add a custom onClick handler.

Is "Cancel" a reserved keyword?

Nope—"Cancel" isn't a JavaScript or ExtendScript reserved keyword. It's just a special text string that Photoshop's dialog system watches for to trigger default button behaviors. Think of it as a convention the scripting engine uses to map common button labels to expected actions.

Example breakdown

Your original code works because:

var button2 = group1.add ("button", undefined);
button2.text = "Cancel";

The engine sees "Cancel" and knows "this button should act as the dialog's cancel control".

After changing to "Can", you have to explicitly define the behavior:

button2.onClick = function() {
  dlg.close();
  dialogResponse = "cancel";
}

This manually replicates the default logic that the system would have provided for the "Cancel" label.

内容的提问来源于stack exchange,提问作者Ghoul Fool

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 19:42:38