Save jpg with path does not work?

ok, I’m not giving up yet, let’s trace our steps.

please paste the following in the console

console.log("PsVer", require("uxp").host.version)
console.log("manifestVersion", require("./manifest.json").manifestVersion)
console.log("localFileSystem", require("./manifest.json").requiredPermissions.localFileSystem)
console.log("lfs", lfs.isFileSystemProvider);
console.log(await lfs.getEntryWithUrl("/Users/myname/Desktop"));
console.log(await lfs.createEntryWithUrl("/Users/myname/Desktop/testfile.jpg"));

and share the result

also, have you tried other locations?

this is the result of the console

file png

ok, we’re getting somewhere
your photoshop version is outdated and does not support getEntryWithUrl
it requires version 24.2+

you will need a different approach that requires the user to pick a folder.

1 Like

Sorry.
I was not aware that you are using a Mac. :scream:

Maher this morning I updated to version 24.2 but it still doesn’t work
here is the screenshot of the console

console

why aren’t you running the last 3 lines?

console.log("lfs", lfs.isFileSystemProvider);
console.log(await lfs.getEntryWithUrl("/Users/myname/Desktop"));
console.log(await lfs.createEntryWithUrl("/Users/myname/Desktop/testfile.jpg"));

sorry for the mistake

you’re just repeating the first 3 lines, 3 times

@haller

Sorry for my earlier response in a Windows environment.

This worked for me.
The first time it asked for permission to save.

I used Photoshop version 24.4.1.
I hope this will be helpful.

      let myDir = await lfs.getEntryWithUrl("Users\\hideo\\Desktop"); //Mac
      let myFile = await myDir.createFile("pollo.jpg", { overwrite: true });
      await app.activeDocument.saveAs.jpg(myFile, { quality: 12 }, true);
1 Like

Maher
when i enter this code i get this in the console

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

error console

https://i.postimg.cc/Px7PLwrz/Schermata-2023-05-09-alle-09-16-41.png

when i enter this code


console.log("PsVer", require("uxp").host.version)
console.log("manifestVersion", require("./manifest.json").manifestVersion)
console.log("localFileSystem", require("./manifest.json").requiredPermissions.localFileSystem)
console.log("lfs", lfs.isFileSystemProvider);
console.log(await lfs.getEntryWithUrl("/Users/myname/Desktop"));
console.log(await lfs.createEntryWithUrl("/Users/myname/Desktop/testfile.jpg"));

this error comes up

in older version of photoshop, you need to start your urls with file:/ or file:\\

in the latest version you don’t have to

Maher I am using version 24.2 so the latest version. what code should i use because i am getting confused.

24.2 is not latest
use file:/ it works with all versions

1 Like

Your error quite clearly tells you which format your path needs to be in.
Is part of the issue perhaps that you’re running PS 24.2 which I assume likes file:, and not the latest stable release which is 24.4.1, which I assume doesn’t want the path prefix?
(I’m guessing a little here as I’m not fully familiar with which feature was added with each release)

1 Like

Maher adding files - works perfectly
I don’t know why it does the important thing that it works

a question
instead of pollo.jpg
I would like to leave the original file name
what string should you add

thanks again for all your help
much appreciated

//getting file name of active document (without extention)
let fileName = path.parse(app.activeDocument.name).name
let myFile = await myDir.createFile(fileName + ".jpg", { overwrite: true });
2 Likes

Maher sorry if I bother you again
this works well for jpg files
if I wanted to use it to save .tif files how should I proceed
I tried changing .jpg
await app.activeDocument.saveAs.jpg(myFile, { quality: 12 }, true);
with .tif
await app.activeDocument.saveAs.tif(myFile, { quality: 12 }, true);
but I don’t get any feedback where I’m wrong,
you have a solution.

As far as I know, TIFF is not (yet) supported by the API. You need to use batchPlay if you want to save as TIFF, e.g. as described in this forum thread.

1 Like

I can’t believe it and since this morning I’ve been going crazy about it and now you tell me it wasn’t planned!!!

crazy stuff
I really can’t like this uxp.

I would like to use await lfs.getEntryWithUrl
to save the tif
how could we proceed,
always can it be done?

Thanks for your post

A friendly advice to save yourself trouble next time is to read the docs carefully. TIFF is not mentioned with a single word.

Also this thread has been marked as resolved a long time ago. If you have unrelated follow-up questions I’d suggest starting a new thread. For your particular question, there are tons of posts if you search on the forum, e.g. this one where I explained the differences between entries and tokens. getEntryWithURL will give you an entry, turn that into a token and pass it to batchPlay.

As a last piece of friendly advice. Start using try/catch and look at your error messages. This would have told you right away that you were calling a non-existent function with “app.activeDocument.saveAs.tif:wink:

1 Like