How to save a jpg into Desktop

I want to save a file to desktop or a file in desktop. In my CEP Plugin I passed “~/Desktop/myfile” and it worked. But in UXP can’t do it. After some research I found,

const fs = require('uxp').storage.localFileSystem;

Supported domains is an array that keeps 3 path I think

(3) [Symbol(userDesktop), Symbol(userDocuments), Symbol(userPictures)]

I wonder how can I use this to save my files to desktop proper way.

My expectation is something like this.

const fs = require('uxp').storage.localFileSystem;
let desktopPath = fs.supportedDomains[0]
app.activeDocument.saveAs.jpg(desktopPath+"/mypic.jpg"{quality: 12},true)

What is the right way to do this action.

Have a nice day


1 Like

Hey there!

The UXP APIs, at the moment, don’t allow for “arbitrary file access”. That means that if you want to save to a location that doesn’t have such access by default (the plugin’s data folder would be one such example), you have to get the user’s permission to write into that folder by using the fs.getFolder(), which opens a folder picker dialog (alternatively, you could also let the user pick a specific file using getFileForSaving).

But you can use the desktop domain as initialDomain in the options using something like this (which makes the desktop folder the default folder in the file picker):

const storage = require('uxp').storage;
const fs = storage.localFileSystem;
const desktopDomain =;

const folder = await fs.getFolder({initialDomain: desktopDomain});
// folder is now a Folder object

Then, you can use folder like any other Folder object (cf. Folder API Reference).

You can also create a persistent token using fs.createPersistentToken(folder) and save that token, e.g., to localStorage to re-use that folder the next time the user uses the plugin without having to re-ask the user for a location.

I hope this helps :slightly_smiling_face:

1 Like

Thank you for detailed answer! Hope to works this time :slight_smile:

1 Like