State of arbitrary file access and shell command support

Good morning! Just wanted to follow up on my own thread. The first topic, that I had brought up, Random File Access, is resolved with release 24.2 (February 2023) and the introduction of the fs module as well as getEntryWithUrl (getEntryWithUrl). I tested this in our pipeline and was able to access both files locally on our Macs as well as network drives (NFS). This is huge! Thanks Adobe for adding these features!!

To enable random file access without ad-hoc user permissions a corresponding setting is necessary in your manifest:

"requiredPermissions": {
    "localFileSystem": "fullAccess"
  }

Here’s an example snippet to get an entry to use with the Photoshop API’s functions relying on tokens (such as app.open()):

const lfs = require("uxp").storage.localFileSystem;
const fileEntry = await lfs.getEntryWithUrl("file:/YOUR_FILE_PATH}");

If you want to read your own files, e.g. configs, text files, etc. (not through Photoshop API functions) you can use the fs module, here are the docs: fs module. Here’s an example snippet to read an ASCII file:

const fs = require("fs");
const data = await fs.readFile("file:/YOUR_FILE_PATH}", options={encoding: "utf-8"});

Note: In case you’re using webpack you have to add fs to your config (as explained here), like:

externals: {
    ...
    fs: 'commonjs2 fs',
    ...
  },

I’m gonna follow up on this thread again once we have updates concerning shell commands. In the meantime I’m gonna mark this as resolved, so that if people come across this thread they get some useful info out of it.

5 Likes