the code was functional only one time, before I need to restart my machine, now it is bugged it is doing the whole job correctly but not exporting anything, though for some reason I had to wait before runing the
const export_and_renameLayer = async (layerID, newLayerName, path) => {
const action = require("photoshop").action;
const core = require("photoshop").core;
console.log("[RENAME TO] :", newLayerName);
console.log("[SAVE IN] :", path);
const listOfDescriptors = [
{
_obj: "select",
_target: [
{
_ref: "layer",
_id: layerID,
},
],
makeVisible: false,
layerID: [layerID],
_isCommand: false,
},
{
_obj: "copyToLayer",
_options: {
dialogOptions: "dontDisplay",
},
},
{
_obj: "set",
_target: [
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum",
},
],
to: {
_obj: "layer",
name: newLayerName,
},
_options: {
dialogOptions: "dontDisplay",
},
},
{
_obj: "select",
_target: [{ _ref: "layer", _name: newLayerName }],
makeVisible: true,
_isCommand: false,
_options: { dialogOptions: "dontDisplay" },
},
{
_obj: "exportSelectionAsFileTypePressed",
_target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" },
fileType: "png",
quality: 32,
metadata: 0,
destFolder: path,
sRGB: true,
openWindow: false,
_options: { dialogOptions: "dontDisplay" },
},
{
_obj: "delete",
_target: [
{
_ref: "layer",
_enum: "ordinal",
_value: "targetEnum",
},
],
layerID: [13],
_options: {
dialogOptions: "dontDisplay",
},
},
];
await wait(50).then(async () => {
await core.executeAsModal(
async () => {
await action.batchPlay(listOfDescriptors, {
modalBehavior: "execute",
synchronousExecution: false,
});
},
{ commandName: `Export ${newLayerName} Layer As PNG start` }
);
});
};
export_and_renameLayer(layerID, "exported_image_name", "/Users/machineName/Desktop/demo/");