this is the script i put together
document.getElementById("btnPopulate").addEventListener("click", test1run);
async function test1() {
const docs = app.documents;
if (!docs || docs.length === 0) {
app.showAlert("No active documents.");
return;
}
for (const doc of docs) {
app.showAlert(`processing ${doc.name}`);
try {
await test();
} catch (error) {
app.showAlert(error);
}
}
}
async function test1run() {
await require('photoshop').core.executeAsModal(test1, {
commandName: 'Action Commands',
})
}
async function bordo() {
let result;
let psAction = require("photoshop").action;
let command = [
{"_obj":"canvasSize","canvasExtensionColorType":{"_enum":"canvasExtensionColorType","_value":"foregroundColor"},"height":{"_unit":"distanceUnit","_value":142.0},"horizontal":{"_enum":"horizontalLocation","_value":"center"},"relative":true,"vertical":{"_enum":"verticalLocation","_value":"center"},"width":{"_unit":"distanceUnit","_value":142.0}}
];
result = await psAction.batchPlay(command, {});
}
async function test() {
await require("photoshop").core.executeAsModal(bordo, {"commandName": "Action Commands"});
}
This is because your batchplay only operates on the active document. In my example, I pass the variable `doc` to the function so the function can operate on each separate document. You are only looping over the documents and logging their info, but not actually doing anything with the reference, so the bathplay is playing 4 times on the active document.
Instead, before you run the batchplay, update the active document and then run it. You should get the result you are after.
Also note, there may be a way to do this with `_target:[{_ref:"document", _id: 123}]` in your batchplay but I am not 100% sure.
const { app, core } = require("photoshop");
const { batchPlay } = require("photoshop").action;
async function doWork(doc) {
return await core.executeAsModal(async () => {
app.activeDocument = doc;
let command = [
{
_obj: "canvasSize",
canvasExtensionColorType: {
_enum: "canvasExtensionColorType",
_value: "foregroundColor",
},
height: { _unit: "distanceUnit", _value: 142.0 },
horizontal: { _enum: "horizontalLocation", _value: "center" },
relative: true,
vertical: { _enum: "verticalLocation", _value: "center" },
width: { _unit: "distanceUnit", _value: 142.0 },
},
];
return await batchPlay(command, {});
});
}
const docs = app.documents;
if (!docs || docs.length === 0) {
app.showAlert("No active documents.");
return;
}
for (const doc of docs) {
console.log(`processing ${doc.name}`);
try {
await doWork(doc);
} catch (error) {
console.error(error);
}
}
