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,
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 = storage.domains.userDesktop;
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).