Save the active psd document in TIFF format in the parent folder of the active document

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!

  1. use executeAsModal
  2. remove "modalBehavior": "fail"
1 Like

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;
1 Like

O, for sure :slight_smile: :rofl:

Ok, now it run correctly, thank you vry much :slight_smile:

1 Like

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

1 Like

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);
}