Hey, I am kinda new to UXP trying it out last week and I opened an image by dragging and dropping in Photoshop (Note the document is not saved) and when I am running the plugin I save the files after changes as a new PNG image but it is asking for the location to save while I want to automatically save to the location from where the Image file was opened in photoshop.
This is my code :
const exportFileName = ${currentDocument.title.replace(/\.[^/.]+$/, "")}_test.png;
// Export the file from the current document
try {
const saveFile = await fs.getFileForSaving(exportFileName, { types: [“png”] });
if (saveFile) {
await currentDocument.saveAs.png(saveFile, {
quality: 100,
interlaced: false,
optimized: true,
transparency: true
});
console.log(`Exported file saved as ${saveFile.nativePath}`);
}
} catch (error) {
console.error(`Could not export the file: ${error.message}`);
}
What should I add or maybe do to put the native location as well in the parameters?
I tried to createfile() as well but it was not working.
You need to retrieve the path of the currently opened document. Unfortunately, fs.getFileForSaving does not support setting the initial path directly. However, you can use the storage APIs to handle file paths and create files directly.
This approach is an old topic, I’ve tried them all, unfortunately it doesn’t seem to be possible. In my case I preferred to save and close the document.