Edit in GitHubLog an issue

photoshopCore

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

Some of these commands can be considered experimental. Some will be integrated into the DOM at a later date. The use of which will then be easier, for example, removing the need to specify the document ID as an argument.

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

Properties

NameTypeMin VersionDescription
apiVersion
number
22.5
API Version declared by the plugin's manifest.json under `host.data.apiVersion` field.

Functions

addNotificationListener

23.3

async : 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
group
string
events
string[]
notifier
NotificationListener

calculateDialogSize

22.5

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

Returns the effective size of a dialog.

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

Parameters

NameType
preferredSize
object
preferredSize.height
number
preferredSize.width
number
identifier?
string
minimumSize?
object
minimumSize.height
number
minimumSize.width
number

convertColor

23.0

RGBColorDescriptor | RGB32ColorDescriptor

Converts the given color (in descriptor form) to RGB, 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
sourceColor
ColorDescriptor
targetModel
ColorConversionModel.RGB

LabColorDescriptor

Convert to Lab

Parameters

NameType
sourceColor
ColorDescriptor
targetModel
ColorConversionModel.Lab

HSBColorDescriptor

Convert to HSB

Parameters

NameType
sourceColor
ColorDescriptor
targetModel
ColorConversionModel.HSB

GrayscaleColorDescriptor

Convert to Grayscale

Parameters

NameType
sourceColor
ColorDescriptor
targetModel
ColorConversionModel.Gray

CMYKColorDescriptor

Convert to CMYK

Parameters

NameType
sourceColor
ColorDescriptor
targetModel
ColorConversionModel.CMYK

createTemporaryDocument

23.0

object

Create a temporary duplicate document for background processing. This document does not appear in the UI, and there are limitations with some editing features.

Copied to your clipboard
await PhotoshopCore.createTemporaryDocument({documentID:123})

Parameters

NameTypeDescription
options
object
Object containing key of "documentID" for the document to duplicate.
options.documentID
number
-

deleteTemporaryDocument

23.0

void

Remove a temporary document.

Copied to your clipboard
await PhotoshopCore.deleteTemporaryDocument({documentID:146})

Parameters

NameTypeDescription
options
object
Object containing key of "documentID" for the document to delete.
options.documentID
number
-

endModalToolState

22.5

async : Promise<void>

End the current modal tool editing state.

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

Parameters

NameType
commit
boolean

executeAsModal

22.5

async : 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, descriptor?: object) => Promise<any>
options

getActiveTool

22.5

async : 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

23.1

CPUInfo

Returns information about the host CPU.

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

getDisplayConfiguration

23.0

Promise<object>

Returns the current display configuration.

Note: returned units differ by platform.

  • Mac uses logical units, points.
  • Windows uses physical units, pixels.
Copied to your clipboard
psCore.getDisplayConfiguration( {physicalResolution: true} )

Parameters

NameTypeDescription
options
object
object Currently only one: physicalResolution. If true, then a property with that name will also appear in the return object.

getGPUInfo

23.1

GPUInfo

Returns OpenGL and OpenCL information about the available graphics processor.

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

getLayerGroupContents

23.1

Promise<{ list: LayerTreeInfo[] }>

Returns a list of the layers contained by the specified layer group.

Copied to your clipboard
await psCore.getLayerGroupContents({"documentID": 123, "layerID": 9})

Parameters

NameType
options
object
options.documentID
number
options.layerID
number

getLayerGroupContentsSync

23.1

object

Returns a list of the layers contained by the specified layer group.

Copied to your clipboard
psCore.getLayerGroupContentsSync({"documentID": 123, "layerID": 9})

Parameters

NameType
options
object
options.documentID
number
options.layerID
number

getLayerTree

23.1

Promise<{ list: LayerTreeInfo[] }>

Returns the full hierarchy of the layer stack in nested "lists".

Copied to your clipboard
await psCore.getLayerTree( {documentID: 123} )

Parameters

NameTypeDescription
options
object
Object containing key of "documentID" for the target document.
options.documentID
number
-

getLayerTreeSync

23.1

object

Returns the full hierarchy of the layer stack in nested "lists".

Copied to your clipboard
psCore.getLayerTree( {documentID: 123} )

Parameters

NameTypeDescription
options
object
Object containing key of "documentID" for the target document.
options.documentID
number
-

getMenuCommandState

22.5

async : Promise<boolean>

Returns whether a command menu item is available for invoking.

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

Parameters

NameType
options
object
options.commandID
number
options.scheduling?
Scheduling

getMenuCommandTitle

22.5

async : 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
options
object
options.commandID?
number
options.menuID?
number
options.scheduling?
Scheduling

getPluginInfo

23.2

async : 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()

getUserIdleTime

23.3

Promise<void>

Return the current number of seconds for user idle time. See also: setUserIdleTime

Copied to your clipboard
await PhotoshopCore.getUserIdleTime()

historySuspended

23.1

Promise<boolean>

Returns true if the history is in a suspended state. See Document.suspendHistory.

Copied to your clipboard
await psCore.historySuspended( {documentID: 123} )

Parameters

NameTypeDescription
options
object
Object containing key of "documentID" for the target document.
options.documentID
number
-

isModal

23.1

boolean

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


performMenuCommand

22.5

async : Promise<boolean>

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

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

Parameters

NameType
options
object
options.commandID
number
options.scheduling?
Scheduling

redrawDocument

24.1

async : Promise<number>

Request that Photoshop redraws (updates) a document immediately. This method can be used to ensure that the document is updated immediately while a user is interacting with a UI element (such as a slider). This can provide a more responsive interaction. Updating a document can be time consuming, and will often happen at a lower frequency than UI events are received. Plugins may therefore want to implement a throttle between UI events and calls to redrawDocument. A throttle could be implemented by using a timer, or by avoiding to call redrawDocument for a small amount of time after a previous request completes. redrawDocument returns the time that it took Photoshop to update the target document in seconds. This number can be used to refine the throttle. redrawDocument is only available to a plugin that is using apiVersion 2 or higher.

Copied to your clipboard
await PhotoshopCore.redrawDocument({ documentID: 123})

Parameters

NameType
options
object
options.documentID
number

removeNotificationListener

23.0

Promise<void>

Detaches a listener from a Photoshop event. See addNotificationListener

Copied to your clipboard
await PhotoshopCore.addNotificationListener('UI', ['userIdle'], onUserIdle)

Parameters

NameTypeDescription
group
string
Notification group.
events
string[]
Array of event names.
notifier
NotificationListener
The Notification Listener to change.

setExecutionMode

23.2

async : 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
options
object
options.enableErrorStacktraces?
boolean
options.logRejections?
boolean

setUserIdleTime

23.3

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
idleTime
number

showAlert

22.5

async : Promise<void>

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

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

Parameters

NameType
options
object
options.message
string

suppressResizeGripper

23.1

Promise<void>

The "resize gripper", a small square in the botton-right corner of a panel, may be hidden by this function. This square will appear above the contents the panel itself including scrollbars. While many panels over the years have simply left space at the bottom to accomodate the gripper, this option removes it.

Copied to your clipboard
await PhotoshopCore.suppressResizeGripper({type: "panel", target: "panel's ID", value: true})

The value for target above will be the id attached to the panel's entry under entrypoints in the plugin manifest.


translateUIString

22.5

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
zstring
string
  • Privacy
  • Terms of Use
  • Do not sell or share my personal information
  • AdChoices
Copyright © 2024 Adobe. All rights reserved.