photoshopAction
The module that facilitates Actions being performed in the UXP-Photoshop world. You may perform your own batchPlay commands, or attach listeners using this module.
const {action} = require('photoshop');
Functions
addNotificationListener
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> async : Promise<void>
Attach a callback function to one or more Photoshop events. The callback has the form (eventName: string, descriptor: ActionDescriptor) => void.
await action.addNotificationListener(['open'], onOpenDocumentHandler);
A table of events is available or the introspection methods described under batchPlay may be employed.
Parameters
eventscallbackbatchPlay
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> Promise<ActionDescriptor[]>
Performs a batchPlay call with the provided commands. Equivalent to an executeAction in ExtendScript.
const target = { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' };
const commands = [{ _obj: 'hide', _target: target }];
await action.batchPlay(commands);
Parameters
batchPlaySync
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.1</span>
<br/> ActionDescriptor[]
Performs a batchPlay call with the provided commands. Equivalent to an executeAction in ExtendScript.
const target = { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' };
const commands = [{ _obj: 'hide', _target: target }];
await action.batchPlay(commands);
Parameters
getIDFromString
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">24.0</span>
<br/> number
Return the identifier number assigned to an action string value. If the string is not already registered, a new ID will be created and returned.
Parameters
valuerecordAction
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">25.0</span>
<br/> Promise<void>
Records this plugin's action to an active Action recording. See Action Recording for usage and manifest requirements.
await action.recordAction({ name: 'My Command', methodName: 'actionHandler'}, {prop: value} );
When the action is invoked, the following top level JavaScript function will be invoked:
async function actionHandler(executionContext, info) {
let propValue = info['prop'];
}
Parameters
optionsremoveNotificationListener
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.0</span>
<br/> Promise<void>
Detaches a listener from a Photoshop event. See addNotificationListener
await action.removeNotificationListener(['open'], onOpenNewDocument);
Parameters
eventslistenervalidateReference
<span class="minversion" style="display: block; margin-bottom: -1em; margin-left: 36em; float:left; opacity:0.5;">23.1</span>
<br/> boolean
Synchronously validates the given action reference, returning true if it still exists. For example, calling this with a closed document would return false.
This feature is intended for advanced developers who understand well how batchPlay works. Validate reference could get handy when you want to add new DOM functionality or use low-level code for performance optimization.
See Action references for details.
Supported reference classes: action, document, channel, layer, guide, historyState, compsClass, path, actionSet
Parameters
ref