Save jpg with path does not work?

i tried various methods but i can’t save the file in the desired folder

this is the script i have available

async function saveJpg() {
    let result;
    let psAction = require("photoshop").action;

    let command = [
{"_obj":"save","as":{"_obj":"JPEG","extendedQuality":10,"matteColor":{"_enum":"matteColor","_value":"none"}},"documentID":59,"in":{"_kind":"local","_path":"/Users/miname/Desktop/AAER/fujifilm_xf_16_80mm_f4.jpg"},"lowerCase":true,"saveStage":{"_enum":"saveStageType","_value":"saveBegin"}},
{"_obj":"save","as":{"_obj":"JPEG","extendedQuality":10,"matteColor":{"_enum":"matteColor","_value":"none"}},"documentID":59,"in":{"_kind":"local","_path":"/Users/miname/Desktop/AAER/fujifilm_xf_16_80mm_f4.jpg"},"lowerCase":true,"saveStage":{"_enum":"saveStageType","_value":"saveSucceeded"}} 
    ];
    result = await psAction.batchPlay(command, {});
}

async function runModalFunction() {
    await require("photoshop").core.executeAsModal(saveJpg, {"commandName": "Action Commands"});
}

await runModalFunction();

please do not send me links to external pages
if you can help me in simple way with working examples

Your _path should be a token. Here’s an internal link with an example

1 Like

Here is another internal link showing how with UXP 7 you can grant arbitrary file access without using tokens.

Thank you both
maybe I explained myself wrong
I need a working script
the ones you put in the links I can’t get them to work
I’m not very experienced in uxp

Thanks for your help

What errors do you get? Please define can’t get them to work part :thinking:

The following is a reference for saving the file with a dialog.
https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/

getFileForSaving()

When saving without user permission, the destination seems to be limited.

getDataFolder()

I am currently aware of the above information.

I don’t understand everything either.
I suggest you check the module section.
https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/

I listened to your suggestions and I managed to save the file in the temporay folder with this code fs.getTemporaryFolder();
and then in the plugin folder with this code fs.getPluginFolder();

Now I would like to be able to save it to a specific location
I tried this but it doesn’t work
maybe i make a mistake
can someone help me

the code below used it to save the file in a folder on the desktop named photo

  const app = require("photoshop").app;
  const fs = await require("uxp").storage.localFileSystem;
  const formats = require("uxp").storage.formats;
  const currentDocument = app.activeDocument;
 const folder = await fs.getEntryWithUrl("file: /Desktop/photo");
const file = await tempFolder.createFile("pollo.jpg", { overwrite: true });
  console.log(file, "fileToken");
  currentDocument.saveAs.jpg(
        file,
        {
          quality: 12,
        },
        true
      );

On line 6 shouldn’t tempFolder just be folder?

If you wrap your code in a try/catch block it’ll report errors in the console for you:

try {
    // Your code goes here
} catch (error) {
    console.log(error)
}

I corrected the error
I put try - catch
but nothing happens I don’t see any errors

Thanks for your help

 try {
  const app = require("photoshop").app;
  const fs = await require("uxp").storage.localFileSystem;
  const formats = require("uxp").storage.formats;
  const currentDocument = app.activeDocument;
 const folder = await fs.getEntryWithUrl("file: /Desktop/photo");
const file = await folder.createFile("pollo.jpg", { overwrite: true });
  console.log(file, "fileToken");
  currentDocument.saveAs.jpg(
        file,
        {
          quality: 12,
        },
        true
      );

    // Your code goes here
} catch (error) {
    console.log(error)
}

saveAs accepts an entry
batchPlay accepts tokens

you don’t need to create a token
also since recently you don’t need to use file: in your URL anymore

Thanks Mayer show me an example of how to proceed, first they tell me that a token is needed now the token is no longer needed, I no longer understand anything about how to save a simple file in a folder.

@haller

Please see here and try it out.
I have not tested them all either.

It appears that UXP requires the Photoshop functionality to go through the modal even when saving files.

SaveAs

The following code saves the currently active file.

const psApp = require('photoshop').app;//app Object
const psCore = require('photoshop').core;//core Object
const fsp = require("uxp").storage.localFileSystem;

async function imgsave() {
  psCore.executeAsModal(async (exeCtrl) => {
    try {
      const file = await fsp.getFileForSaving("image.jpg");
      psApp.activeDocument.saveAs.jpg(file, { quality: 12 }, true);
    } catch (e) {
      console.log(e);
    }
  }, { "commandName": "test" });
}

imgsave();

When saving text, it was not necessary to go through the modal.
If it is helpful.

when working with batchPlay you need to provide a token in place of _path
a token is a string generated from an entry

for other methods like saveAs you don’t have to, you just use the entry directly

const {app,core: { executeAsModal }} = require("photoshop");
const {storage: { localFileSystem: lfs }} = require('uxp');

executeAsModal(async()=>{
   let myDir = await lfs.getEntryWithUrl("D:\\")
   let myFile = await myDir.createFile("pollo.jpg", { overwrite: true });
   await app.activeDocument.saveAs.jpg(myFile, {quality: 12}, true);
})

lastly for this code to work you’ll need to use the correct manifest

"manifestVersion": 5,
 ...
"requiredPermissions": {
    ...
    "localFileSystem": "fullAccess",
    ...
  }

setting requiredPermissions > localFileSystem to fullAccess is neccesary for getEntryWithUrl to work, otherwise you’ll need to use file pickers to generate an entry

1 Like

hideo
i tried your code, but it pops me the save as window, i would like to save the file without the save as window appearing.

Maher
i tried your code, but nothing happens it doesn’t save anything
I use mac instead of D:// I put /Users/myname/Desktop

for the manifest I continued as you suggested

I don’t understand where I can go wrong
everything seems alright

{
  "id": "com.adobe.secure-storage-sample",
  "name": "secure-storage-sample",
  "version": "1.0.0",
  "main": "index.html",
  "host": [
    {
      "app": "PS",
      "minVersion": "23.0.0"
    }
  ],
  "requiredPermissions": {
  "localFileSystem": "fullAccess"
  }
  ,
  "main": "index.html",
  "manifestVersion": 5,
  "requiredPermissions": {
    "network": {
      "domains": [
        ""
      ]
    },
    "clipboard": "readAndWrite",
    "localFileSystem": "request",
    "ipc": {
      "enablePluginCommunication": true
    }
  },
  "entrypoints": [
    {
      "type": "panel",
      "id": "vanilla",

in your manifest you have duplicate requiredPermissions entries with the latter having localFileSystem set to request.

try removing the first and setting the one left to fullAccess

so you end up with one requiredPermissions object

"requiredPermissions": {
    "network": {
      "domains": [
        ""
      ]
    },
    "clipboard": "readAndWrite",
    "localFileSystem": "fullAccess",
    "ipc": {
      "enablePluginCommunication": true
    }
  },
1 Like

Maher thank you for all the support you give me
unfortunately it doesn’t work yet

I corrected this way

{
  "id": "com.adobe.secure-storage-sample",
  "name": "secure-storage-sample",
  "version": "1.0.0",
  "main": "index.html",
  "host": [
    {
      "app": "PS",
      "minVersion": "23.0.0"
    }
  ],
  "main": "index.html",
  "manifestVersion": 5,
  "requiredPermissions": {
    "network": {
      "domains": [
        ""
      ]
    },
    "clipboard": "readAndWrite",
    "localFileSystem": "fullAccess",
    "ipc": {
      "enablePluginCommunication": true
    }
  },
  "entrypoints": [
    {
      "type": "panel",
      "id": "vanilla",

please run this code (after editing “myname” in the path) and share your console output
you can access the console by clicking debug in the Developer Tool

const {app,core: { executeAsModal }} = require("photoshop");
const {storage: { localFileSystem: lfs }} = require('uxp');
try {
    await executeAsModal(async()=>{
        let myDir = await lfs.getEntryWithUrl("/Users/myname/Desktop")
        console.log("myDir")
        console.log(myDir)
        console.log("-----------------")
        let myFile = await myDir.createFile("pollo.jpg", { overwrite: true });
        console.log("myFile")
        console.log(myFile)
        console.log("-----------------")
       await app.activeDocument.saveAs.jpg(myFile, {quality: 12}, true);
     })
} catch (error) {
    console.log(error)
}

1 Like

@haller

I was able to save by specifying the full path as follows
Please review the path description.
Try it once.

let myDir = await lfs.getEntryWithUrl("C:/Users/myname/Desktop")
or
let myDir = await lfs.getEntryWithUrl("C:\\Users\\myname\\Desktop")

*If you are using OneDrive, note that it will not be saved to the OneDrive desktop.

@Maher

Thank you for your valuable information.
It was helpful for me too.

Maher I did as you told me
unfortunately it doesn’t work
Debugging doesn’t show any errors

hideo
i use mac the path you provided doesn’t work for me
anyway thanks for sharing