Edit in GitHubLog an issue

Photoshop

The top level application object, root of the Photoshop DOM

Copied to your clipboard
const app = require('photoshop').app

From here you can access open documents, tools, UI elements and run commands or menu items.

Properties

名称类型访问最低版本描述
actionTreeActionSet[]R23.0Returns the action tree shown in Actions panel, as an array of ActionSets, each containing Actions.
activeDocumentDocumentR W23.0The current document that has the application's focus.
backgroundColorSolidColorR23.0The background color and color style for documents.
currentToolToolR23.0Current selected tool. For now, the Tool class is an object with only an `id` field. In the future, we aim to provide tools with their own classes.
displayDialogsDialogModesR W23.0The dialog mode for the application, which controls what types of dialogs should be displayed when your code is interacting with Photoshop.
documentsDocumentsR23.0A list of the documents currently open.
fontsTextFontsR23.0The fonts installed on this system.
foregroundColorSolidColorR W23.0The foreground color (used to paint, fill, and stroke selections).
preferencesPreferencesR24.0Contains Photoshop preferences grouped into several categories similar to the Preferences dialog.
typenamestringR23.0The class name of the referenced object: "Photoshop".

Methods

batchPlay

23.0

Promise<ActionDescriptor[]>

At the heart of all our APIs is batchPlay. It is the evolution of executeAction. It accepts ActionDescriptors deserialized from JS objects, and can play multiple descriptors sequentially without updating the UI. This API is subject to change and may be accessible in other ways in the future.

Parameters

名称类型
commandsany
optionsany

bringToFront

23.0

void

Brings application to focus, useful when your script ends, or requires an input.


convertUnits

23.4

number

Convert the given value from one unit to another. Available units are: Constants.Units.{CM, MM, INCHES, PIXELS, POINTS, PICAS}. Use Document.resolution when converting from or to PIXELS. For example, use this routine for converting a document's width from pixels to inches.

Copied to your clipboard
1// convert the current document's width to inches
2const exportDoc = psApp.activeDocument;
3let widthInInches = psApp.convertUnits(exportDoc.width,
4 Constants.Units.PIXELS,
5 Constant.Units.INCHES,
6 exportDoc.resolution);
7

Parameters

名称类型描述
fromValuenumberThe value that is to be converted.
fromUnitsUnitsThe unit that the fromValue is in. Use Constants.Units for valid values.
toUnitsUnitsThe unit that the return value is in. Use Constants.Units for valid values.
resolution?numberThe pixels per inch value to use when converting to and from pixel values.

createDocument

23.0

async : Promise<Document>

创建一个新的文件。

没有选项将创建一个每英寸300像素的7×5英寸的文档。 这与 "Photoshop默认尺寸 "的预设相同。

一个带有 "预设 "字符串参数的对象可以用来指定任何 其他预设,这些预设随Photoshop安装或由用户创建。

一个带有一个或多个参数的对象也可以被提供。任何参数 缺少将被设置为默认的:宽度2100像素,高度1500像素。 分辨率300像素/英寸,模式。模式:@RGBColorMode和白色填充,无透明度。 无透明度。

Copied to your clipboard
1// "默认的Photoshop大小 "7x5英寸,300ppi
2let newDoc1 = await app.documents.add();
3let newDoc2 = await app.documents.add({
4 width: 800,
5 height: 600,
6 resolution: 300,
7 mode: "RGBColorMode",
8 fill: "transparent"
9});
10let newDoc3 = await app.documents.add({preset: "My Default Size 1"});

Parameters

名称类型描述
options?DocumentCreateOptions@DocumentCreateOptions

getColorProfiles

24.1

string[]

已安装的颜色配置文件列表,适用于RGB和灰度模式。

Parameters

名称类型默认值描述
colorModestring'RGB'Specify which color mode's profiles to list. (default: "RGB", options: "Gray")

open

23.0

async : Promise<Document>

Opens the specified document and returns the model

*注意,这个API需要一个UXPFileEntry 作为其参数的对象。

Copied to your clipboard
1// 打开一个已选定的文件
2let entry = await require('uxp').storage.localFileSystem.getFileForOpening()
3const document = await app.open(entry);
4
5// 显示打开文件的对话框
6const document = await app.open();

Parameters

名称类型
entry?File

showAlert

23.0

Promise<void>

在Photoshop中显示一个带有确定信息的警告。

Parameters

名称类型
messagestring
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2023 Adobe. All rights reserved.