I’ve had a few occurrences where using batch play with multiple descriptors in the same batch play doesn’t work as it should. Splitting it up into multiple batchPlay descriptors fixes the issue. One time, it worked correctly on my PC and not Mac but can’t remember which exact descriptor that was.
Here is one example that I just ran into. In this case, it is a pretty specific situation that doesn’t work correctly. I have a 1 layer file that is NOT a background layer. I’m adding a new layer and moving the layer to the bottom. When putting both descriptors into the same batchPlay, it will create the new layer but it won’t move it to the bottom. However, if I split it out into 2 batchPlay descriptors it works correctly.
I thought initially that maybe the descriptors within the batch play were running asynchronously with each other and the move was happening before the new layer could be created. To test this, I ran the same batch play with a document that had 2 layers to start with to see if the top layer moved to the bottom before the new layer was created. However, in that case, it runs correctly to create a new layer and move it to the bottom below the other 2 layers.
Here is the code that doesn’t work. Again, this doesn’t work ONLY if running on a single layer document. Of coarse, the single layer isn’t a background layer.
const batchPlay = require("photoshop").action.batchPlay;
await batchPlay(
[
{
"_obj": "make",
"_target": [
{
"_ref": "layer"
}
],
"using": {
"_obj": "layer",
"name": "Background Image"
},
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
},
{
"_obj": "move",
"_target": [
{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"to": {
"_ref": "layer",
"_enum": "ordinal",
"_value": "back"
},
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
Here is the modified version that works for a single layer document. The descriptors are identical, just in 2 batchPlay commands.
const batchPlay = require("photoshop").action.batchPlay;
await batchPlay(
[
{
"_obj": "make",
"_target": [
{
"_ref": "layer"
}
],
"using": {
"_obj": "layer",
"name": "Background Image"
},
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
await batchPlay(
[
{
"_obj": "move",
"_target": [
{
"_ref": "layer",
"_enum": "ordinal",
"_value": "targetEnum"
}
],
"to": {
"_ref": "layer",
"_enum": "ordinal",
"_value": "back"
},
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
],{
"synchronousExecution": false,
"modalBehavior": "fail"
});
I’ve had similar issues a couple of other times and if I can figure out which exact descriptors they were I will post an update. Right now, I am gun shy to use multiple descriptors in the same batchPlay because I’m afraid it may work OK on my computer but not on all of the users computers. Therefore, I have started to just use one descriptor per batchPlay command. Hope this info help for the developer team to troubleshoot.