Open file picker via getFileForOpening with string path

Hi, I want the file picker to be opened with a preselected file.
I understand, that because of security reasons, only files in predefined folders can be opened without user interaction. For my use case it’s okay to open the file picker and let the user click the open button. But I want to help the user by preselecting a specific file.
I hoped, that fs.getFileForOpening({initialLocation: "/Users/<username>/myFilePathString.psd"}) could help but the function only accepts File or Folder.
Is there another possibility?

Best regards

1 Like

Hi Lars,
according to this you can use domains, which you have to import first, e.g.

const fs = require('uxp').storage.localFileSystem;
const domains = require('uxp');
const f = await fs.getFileForOpening({initialDomain: domains.userDocuments});

It seems like you can use initialLocation only with Files and Folders that have already been selected earlier…

Also, most of the documented domains don’t seem to work yet.


Thanks Davide for your reply!
My example was not really very well chosen since the important thing is not, that the file for opening is in the user’s directory but is a path to an existing file somewhere on the disk. The ideal handling for me would be to call getFileForOpening with the path and if the file exists it is pre-selected, if not, a default folder is opened instead.
My current workaround is to let the OS open that file.

Best regards