I use select and export in batch play
import { action, core, app} from 'photoshop';
import { Layer} from 'photoshop/dom/Layer';
//
export const exportLayerAsPng = async (layer:Layer, path:string, imageSuffix:string): Promise<void> => {
const { id, name } = layer;
console.log("exportLayerAsPng",imageSuffix, name);
console.log("", path)
const selectCommand = {
_obj: 'select',
_target: [
{
_ref: 'layer',
_id: id,
},
],
makeVisible: false,
layerID: [id],
_isCommand: false,
}
//
const exportCommand = {
_obj: 'exportSelectionAsFileTypePressed',
_target: { _ref: 'layer', _enum: 'ordinal', _value: 'targetEnum' },
fileType: 'png',
quality: 32,
metadata: 0,
destFolder: path, //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.name} Layer As PNG start` }
);
};