# Save jpg with path does not work?

**URL:** <https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263>\
**Category:** Photoshop\
**Created:** [May 4, 2023, 10:41am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263 "2023-05-04T10:41:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 4, 2023, 10:41am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/1 "2023-05-04T10:41:17Z")

</div>

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

this is the script i have available

```auto
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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [May 4, 2023, 11:09am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/2 "2023-05-04T11:09:18Z")

</div>

Your `_path` should be a token. Here’s an [internal link](http://forums.creativeclouddeveloper.com/t/how-do-i-save-a-file-with-batchplay-to-the-temporary-folder/4105/4) with an example

---

<div class="post-metadata">

**Author:** ![Timothy\_Bennett](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/timothy_bennett/32/1251_2.png) [@Timothy\_Bennett](https://forums.creativeclouddeveloper.com/u/Timothy_Bennett)\
**Post date:** [May 4, 2023, 11:13am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/3 "2023-05-04T11:13:21Z")

</div>

Here is another [internal link](http://forums.creativeclouddeveloper.com/t/state-of-arbitrary-file-access-and-shell-command-support/5720/4) showing how with UXP 7 you can grant arbitrary file access without using tokens.

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 4, 2023, 11:30am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/4 "2023-05-04T11:30:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [May 4, 2023, 11:36am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/5 "2023-05-04T11:36:03Z")

</div>

What errors do you get? Please define _can’t get them to work_ part 🤔

---

<div class="post-metadata">

**Author:** ![hideo](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/hideo/32/3329_2.png) [@hideo](https://forums.creativeclouddeveloper.com/u/hideo)\
**Post date:** [May 4, 2023, 1:26pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/6 "2023-05-04T13:26:55Z")

</div>

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/](https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/)

[getFileForSaving()](https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#getfileforsavingsuggestedname-options)

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

[getDataFolder()](https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#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/](https://developer.adobe.com/photoshop/uxp/2022/uxp-api/reference-js/Modules/)

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 10:34am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/7 "2023-05-05T10:34:01Z")

</div>

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

```auto
  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
      );

```

---

<div class="post-metadata">

**Author:** ![Timothy\_Bennett](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/timothy_bennett/32/1251_2.png) [@Timothy\_Bennett](https://forums.creativeclouddeveloper.com/u/Timothy_Bennett)\
**Post date:** [May 5, 2023, 11:12am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/8 "2023-05-05T11:12:58Z")

</div>

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:

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

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 11:20am UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/9 "2023-05-05T11:20:48Z")

</div>

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

Thanks for your help

```auto
 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)
}

```

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [May 5, 2023, 12:13pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/10 "2023-05-05T12:13:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 12:44pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/11 "2023-05-05T12:44:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hideo](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/hideo/32/3329_2.png) [@hideo](https://forums.creativeclouddeveloper.com/u/hideo)\
**Post date:** [May 5, 2023, 1:22pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/12 "2023-05-05T13:22:50Z")

</div>

@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](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/document/#saveas)

The following code saves the currently active file.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [May 5, 2023, 1:30pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/13 "2023-05-05T13:30:00Z")

</div>

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

```auto
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

```auto
"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

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 5:04pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/14 "2023-05-05T17:04:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 5:08pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/15 "2023-05-05T17:08:06Z")

</div>

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

```auto
{
  "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",

```

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [May 5, 2023, 5:25pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/16 "2023-05-05T17:25:18Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 5, 2023, 6:38pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/17 "2023-05-05T18:38:48Z")

</div>

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

I corrected this way

```auto
{
  "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",

```

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [May 6, 2023, 7:25pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/18 "2023-05-06T19:25:27Z")

</div>

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

```auto
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)
}

```

---

<div class="post-metadata">

**Author:** ![hideo](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/hideo/32/3329_2.png) [@hideo](https://forums.creativeclouddeveloper.com/u/hideo)\
**Post date:** [May 7, 2023, 5:58pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/19 "2023-05-07T17:58:11Z")

</div>

@haller

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [May 7, 2023, 7:06pm UTC](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263/20 "2023-05-07T19:06:24Z")

</div>

> [@hideo](#):
>
> `let myDir = await lfs.getEntryWithUrl("C:\\Users\\myname\\Desktop")`

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

[Next page](https://forums.creativeclouddeveloper.com/t/save-jpg-with-path-does-not-work/6263.md?page=2)
