I tried to export the selected Layer. Sometimes it does work, but sometimes it doesn’t. The result of the batchPlay is just an empty {}
"requiredPermissions": {
"localFileSystem": "fullAccess"
},
let layerID = app.activeDocument.layers[0].id //Assume the first layer to export
let tempFolder = await fs.getTemporaryFolder();
console.log(tempFolder.nativePath);
const selectCommand = {
_obj: "select",
_target: [
{
_ref: "layer",
_id: layerID,
},
],
makeVisible: false,
layerID: [layerID],
_isCommand: false,
};
const exportCommand = {
_obj: "exportSelectionAsFileTypePressed",
_target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" },
fileType: "png",
quality: 32,
metadata: 0,
destFolder: tempFolder.nativePath, //destFolder.nativePath,
sRGB: true,
openWindow: false,
_options: { dialogOptions: "dontDisplay" },
};
await core.executeAsModal(
async () => {
await action.batchPlay([selectCommand, exportCommand], {
modalBehavior: "execute",
synchronousExecution: false,
});
},
{ commandName: `Export Layer As PNG` }
);