I didn’t include any code as I didn’t want to just post other people’s code (I’ve just been trying code snippets directly from the forums to see if I can get anything to work), however here are the two topics I have referenced and directly tried:
I’ve taken the code as is and modified it with any additions in the replies that supposedly make it work. The code was put in an async function being called on the click event of a button.
From my understanding after doing more research, ExecuteAsModal is required in API 2, though I’ve found the documentation on this a bit hard to follow.
As a place to start though, here’s a sample I’ve put together that doesn’t work based on output from Alchemist:
async function OnExportButtonClick()
{
const fs = require("uxp").storage.localFileSystem;
const persistentFolder = await fs.getFolder();
const newFile = await persistentFolder.createFile("texture.png", { overwrite: true });
const saveFile = await fs.createSessionToken(newFile);
const batchPlay = require("photoshop").action.batchPlay;
const result = await batchPlay(
[
{
_obj: "save",
as: {
_obj: "fnord SuperPNG",
$pngC: 9,
$pngF: 248,
$pngS: 0,
$pngQ: false,
$pngA: {
_enum: "$alfT",
_value: "$alfC"
},
$pngX: false,
$pngI: false,
$pngM: true
},
in: {
_path: saveFile,
_kind: "local"
},
documentID: 219,
copy: true,
lowerCase: true,
alphaChannels: false,
saveStage: {
_enum: "saveStageType",
_value: "saveBegin"
},
_options: {
dialogOptions: "dontDisplay"
}
}
],{
synchronousExecution: false,
modalBehavior: "fail"
});
}