Yes, I want to save it in “pippo”, I don’t receive errors, but the promise state is “fulfilled” and the promise result is “undefined”
ok got it!
- use
executeAsModal
- remove
"modalBehavior": "fail"
it’s a good practice to wrap your code in a try/catch to see errors.
I have received the error: “ncaught ReferenceError: batchPlay is not defined
at :17:16”
const batchPlay = require("photoshop").action.batchPlay;
also see this
I use execute as modal in my example above.
const core = require('photoshop').core;
const executeAsModal = core.executeAsModal;
O, for sure
Ok, now it run correctly, thank you vry much
i dont know why, but now stopped working and generate the error:
saveFile is not defined.
this is the code:
const app = window.require('photoshop').app
const batchPlay = require('photoshop').action.batchPlay;
const fs = require('uxp').storage.localFileSystem;
//const core = require('photoshop').core;
//const executeAsModal = core.executeAsModal;
token = await JSON.parse(localStorage.getItem("fixfolder")); //seleziona il token salvato
const folder = await fs.getEntryForPersistentToken(token); //estrae il percorso della cartella persistente
const subfolder = await folder.createFolder("pippo"); //Crea le cartelle desiderate e le sottocartelle)
const subsubfolder = await subfolder.createFolder("paperino");
//crea il file in modalità modale
require('photoshop').core.executeAsModal(async () => {
const newFile = await subfolder.createFile("newfile.tif", { overwrite: true });
const saveFile = await fs.createSessionToken(newFile);
});
const result = await batchPlay(
[
{
"_obj": "save",
"as":
{
"_obj": "TIFF",
"byteOrder":
{
"_enum": "platform",
"_value": "IBMPC"
},
"layerCompression":
{
"_enum": "encoding",
"_value": "RLE"
}
},
"in": {
"_path": saveFile,
"_kind": "local"
}
}
], {
"synchronousExecution": false,
//"modalBehavior": "fail"
});
i think that i changed nothing, but noiw say me that error
You moved batchPlay outside of exeModal. It should be inside
It works now, but it was also out before!
Thank you
Re your point that save operations require executeAsModal: I’m able to save the current document as JPEG without using executeAsModal. This works fine for me:
const save_image_as_JPEG = {
_obj: "save",
as: {
_obj: "JPEG",
extendedQuality: image_save_quality,
matteColor: {
_enum: "matteColor",
_value: "none",
},
},
copy: true,
in: {
_path: outputFileToken,
_kind: "local"
}
};
try {
await app.batchPlay([save_image_as_JPEG]);
} catch (error) {
console.error(`Error during image save`, error);
}