Edit in GitHubLog an issue

photoshopCore

The module that allows access to specialized commands within the application. Various application state can be modified or queried here.

Copied to your clipboard
var PhotoshopCore = require('photoshop').core;

Variables#

apiVersion#

Let apiVersion: number

API Version declared by the plugin's manifest.json under host.data.apiVersion field.

If value 1, you will have access to Photoshop 22.0 DOM and be able to make mutable calls outside a modal state. If 2, you will have access to latest DOM, modal execution and everything else new we're adding.

Functions#

addNotificationListener#

Promise<void>

Attach a listener to a Photoshop core event. A callback in the form of (eventName: string, descriptor: Descriptor) => void will be performed. The event(s) below are supported:

group: 'UI', event: 'userIdle'

  • Invoked after the Photoshop user idles for a specified number of seconds. See setUserIdleTime.
  • Invoked a second time with the descriptor {idleEnd: true} if the user is no longer idle. This signal can be used to finish up tasks being performed during the idle time.
Copied to your clipboard
await PhotoshopCore.addNotificationListener('UI', ['userIdle'], onUserIdle)

Parameters#

NameType
groupstring
eventsstring[]
notifierNotificationListener

calculateDialogSize#

Promise<{ height: number ; width: number }>

Returns the effective size of a dialog.

Copied to your clipboard
1var idealSize = { width: 200, height: 500 }
2{ width, height} = await PhotoshopCore.calculateDialogSize(idealSize)

Parameters#

NameType
preferredSizeobject
preferredSize.heightnumber
preferredSize.widthnumber
identifier?string
minimumSize?object
minimumSize.heightnumber
minimumSize.widthnumber

convertColor#

ColorDescriptor

Converts the given color (in descriptor form) to the given color space, returning the color descriptor.

This is an internal API that is used for SolidColor and all the other color classes.

Currently, this API uses the application color settings for conversion (Edit > Color Settings...). ' In the future, we will provide color conversion based on embedded color profiles.

Parameters#

NameType
sourceColorColorDescriptor
targetModelColorConversionModel

endModalToolState#

Promise<void>

End the current modal tool editing state.

Copied to your clipboard
1// close the modal dialog, cancelling changes
2await PhotoshopCore.endModalToolState(false)

Parameters#

NameType
commitboolean

executeAsModal#

Promise<void>

ExecuteAsModal is needed when a plugin wants to make modifications to the Photoshop state. This includes scenarios where the plugin wants to create or modify documents, or the plugin wants to update UI or preference state.

ExecuteAsModal is only available to plugin that is using apiVersion 2 or higher.

See Modal Execution for details

Parameters#

NameType
targetFunction(executionContext: ExecutionContext) => Promise<any>
optionsExecuteAsModalOptions

getActiveTool#

Promise<{ classID: string ; isModal: boolean ; key: string ; title: string }>

Returns information about the active Photoshop tool.

Copied to your clipboard
{ title } = await PhotoshopCore.getActiveTool()

getCPUInfo#

CPUInfo

Returns information about the host CPU.

Copied to your clipboard
1{ logicalCores, frequencyMhz, vendor } = PhotoshopCore.getCPUInfo()
2var isAMD = vendor === "AMD"
3var isARM = vendor === "ARM"

getGPUInfo#

GPUInfo

Returns OpenGL and OpenCL information about the available graphics processor.

Copied to your clipboard
1{ gpuInfoList, clgpuInfoList } = PhotoshopCore.getGPUInfo()
2console.log(JSON.stringify(gpuInfoList))
3// > [{"version":"2.1 ATI-4.5.14","memoryMB":8192,"name":"16915464", ...}]
4console.log(JSON.stringify(clgpuInfoList))
5// > [{"version":"OpenCL 1.2 ","memoryMB":8589,"name":"AMD Radeon Pro 580X Compute Engine", ...}]

getMenuCommandState#

Promise<boolean>

Returns whether a command menu item is available for invoking.

Copied to your clipboard
1// can a Fill be performed?
2var canFill = await PhotoshopCore.getMenuCommandState({ commandID: 1042 })

Parameters#

NameType
optionsobject
options.commandIDnumber
options.scheduling?Scheduling

getMenuCommandTitle#

Promise<string>

Returns the localized menu title of the menu command item.

Copied to your clipboard
var renameLayerStr = await PhotoshopCore.getMenuCommandTitle({ commandID: 2983 })

Parameters#

NameType
optionsobject
options.commandID?number
options.menuID?number
options.scheduling?Scheduling

getPluginInfo#

Promise<ActionDescriptor>

Return information about the execution of the plugin. This method is intended for developing plugins. Shipping code should not use this method.

The returned information include the following properties:

numberOfPendingMainThreadTasks: Number of pending promises.

batchPlayCount: Number of batchPlay calls since the plugin was loaded.

mainThreadTimeOutCount: Number of JavaScript calls that have timed out. This is typically caused by executing commands while Photoshop is modal without using executeAsModal.

v8HeapSize: V8 heap allocated for the plugin. This number is only accurate when loading plugins through the UXP Developer Tool.

Copied to your clipboard
await PhotoshopCore.getPluginInfo()

isModal#

boolean

Returns true if the plugin is currently in a modal state using executeAsModal


performMenuCommand#

Promise<boolean>

Invokes the menu command via its commandID. Returns false on failure, or if the command is not available.

Copied to your clipboard
1// select all
2await PhotoshopCore.performMenuCommand({ commandID: 1017 })

Parameters#

NameType
optionsobject
options.commandIDnumber
options.scheduling?Scheduling

setExecutionMode#

Promise<void>

The execution mode can be used while debugging a plugin. It is only available when the developer mode is enabled.

The following example illustrate how to enable stacktraces for batchPlay commands that fail. When stacktraces are enabled, then an error result descriptor from a batchPlay request will include a stacktrace property. The property can be used when reporting bugs to Adobe.

Copied to your clipboard
await PhotoshopCore.setExecutionMode({ enableErrorStacktraces: true })

The following illustrates how to enable console warnings when a promise is rejected:

Copied to your clipboard
await PhotoshopCore.setExecutionMode({ logRejections: true })

Parameters#

NameType
optionsobject
options.enableErrorStacktraces?boolean
options.logRejections?boolean

setUserIdleTime#

Promise<void>

Specifies the number of seconds a user must be idle on Photoshop before invoking the userIdle event handler defined with addNotificationListener. An idleTime of 0 turns off idle notifications.

Copied to your clipboard
await PhotoshopCore.setUserIdleTIme(3)

Parameters#

NameType
idleTimenumber

showAlert#

Promise<void>

Show a generic alert box to the user. 'OK' to dismiss.

Copied to your clipboard
1// script has completed.
2await PhotoshopCore.showAlert({ message: 'Operation successful'})

Parameters#

NameType
optionsobject
options.messagestring

translateUIString#

string

Given a Photoshop ZString (of format "$$$/slash/separated/key=english default value"), will return the translated string for the current UI language

Parameters#

NameType
zstringstring
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.