Confusion over automatically importing a file/multiple files

Hi Everyone,

I’ve been looking into how to properly import files as layers to be edited. I can record what’s going on via the batchplay method, but I am having trouble understanding how tokens are passed, and how the open file dialogue works, so that this can be automatically performed.

I’ve seen a thread with similar wishes here: How do you place an image from the local file system using BatchPlay?, but I was having trouble parsing what was done.

let entry = await fs.getFileForOpening();
let token = fs.createSessionToken(entry);
localStorage.setItem("this/is/the/file/path", token);

const batchCommands = [
...
{
        "_obj": "placeEvent",
        "ID": 482,
        "null": {
            "_path": token,
            "_kind": "local"
        },
...
}
...

The promise returned from this batchplay was fulfilled, but PS remained stuck in the “file open” dialogue. Is there any way to automatically get the file imported as a layer? I’m wishing to process hundreds of images.

you could pass option into dialog to allow selection of multiple files: https://developer.adobe.com/xd/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/

Then it should return array of files. And you would create token for each file in array and then pass it into batch play commands.

Thanks for this info! I’ll give this a try so I can improve the import process to something other than “drag from finder into photoshop”