I tried writing in batchPlay, but in both cases time taken was 6 msec or so for 253 actions. The numbers were too small to tell the difference in speed.
{"actions": 253, "timeTaken": 6, "os": "darwin", "osVersion": "20.6.0", "psVersion": "24.3.0"}
import photoshop from 'photoshop' ;
const { batchPlay } = photoshop.action ;
/**
* get length of action sets
* @return {Promise<Number>}
*/
export const countActionSets = async () => {
const retval = await batchPlay([
{
"_obj": "get",
"_target": [
{
"_property": "numberOfActionSets",
},
{
"_ref": "application",
"_enum": "ordinal",
"_value": "targetEnum",
},
],
"_options": {
"dialogOptions": "dontDisplay",
},
},
],
{},
) ;
return retval[0].numberOfActionSets ;
} ;
/**
* get the descriptor of an action set by index
* @param {Number} index 1-based index of the target action set
* @return {Promise<Object>} {name: String, itemIndex: Number, count: Number, numberOfChildren: Number, ID: Number}
*/
export const getActionSetByIndex = async (index) => {
const retval = await batchPlay([
{
"_obj": "get",
"_target": [
{
"_ref": "actionSet",
"_index": index,
},
],
},
],
{},
) ;
return retval[0] ;
} ;
/**
* get all actions under action set
* @param {Object} actionSetDesc descriptor of target action set
* @return {Promise<Array>} [{name: String, ID: Number, parentName: String}...]
*/
export const getActions = async (actionSetDesc) => {
const retval = await batchPlay([
{
"_obj": "multiGet",
"_target": {
"_ref": [
{
"_ref": "actionSet",
"_id": actionSetDesc.ID,
},
],
},
"extendedReference": [
["name", "ID", "parentName"],
{
"_obj": "action",
"index": 1,
"count": -1,
},
],
"options": {
"failOnMissingProperty": false,
"failOnMissingElement": false,
},
},
],
{},
) ;
return retval[0].list ;
} ;
/**
* get all action sets and actions under them
* @return {Promise<Array>} [{name: String, ID: Number, actions: Array}...]
*/
export const getAllActionSet = async () => {
const actionSetLength = await countActionSets() ;
const actionSets = [] ;
for(let i = 1 ; i <= actionSetLength ; i++) {
const currentActionSet = await getActionSetByIndex(i) ;
const actions = await getActions(currentActionSet) ;
const outgoingObject = {
name: currentActionSet.name,
ID: currentActionSet.ID,
actions,
}
actionSets.push(outgoingObject) ;
}
return actionSets ;
} ;