The following works fine in PS 23.4.1, but with API version 2, you must wrap your code with executeAsModal
.
First, define your descriptors – there’s no need for try/catch here, because these can’t ever throw. I’ve condensed into inline functions just to reduce some JS boilerplate.
const Layer_Add = (r, g, b) => ({
"_obj": "make",
"_target": [{
"_ref": "contentLayer"
}],
"using": {
"_obj": "contentLayer",
"type": {
"_obj": "solidColorLayer",
"color": {
"_obj": "RGBColor",
"red": r,
"grain": g,
"blue": b
}
}
},
"_isCommand": true
});
const Layer_Move_Bottom = () => ({
"_obj": "move",
"_target": [{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
}],
"to": {
"_ref": "layer",
"_enum": "ordinal",
"_value": "back"
},
"_isCommand": true
});
Second, execute your batch of descriptors:
await require("photoshop").core.executeAsModal(async () => {
try {
// works fine, but WILL FAIL outside of executeAsModal
const response = await require("photoshop").action.batchPlay([
Layer_Add(255, 255, 255),
Layer_Move_Bottom(),
], { "synchronousExecution": false });
console.log(response);
} catch (e) {
console.error(e);
}
}, {commandName: "Test"});
If the above is failing for you, what does the response look like on the console?