BatchPlay is failing to process descriptors containing "_obj": "runJavaScript"

Hi everyone,

I am developing a feature for my plugin that downloads remote .psjs files and executes them locally. However, I’ve run into an issue where batchPlay fails to execute the code.

Here is my current function:

JavaScript

async function runPSJS(path) {
    const fs = require('uxp').storage.localFileSystem;
    const token = await fs.createSessionToken(await fs.getEntryWithUrl("plugin-data:/" + path));
    
    return await action.batchPlay([
        {
            "_obj": "runJavaScript",
            "_target": [{ "_enum": "ordinal", "_ref": "application", "_value": "targetEnum" }],
            "file": { "_kind": "local", "_path": token }
        }
    ], {
        continueOnError: true
    });
};

The problem: I used the Actions Panel to record the step and converted it using the native “Copy as JavaScript” feature. The action works perfectly when played directly from the Actions Panel, but it does nothing (fails to execute) when triggered via batchPlay in my UXP code.

Environment:

  • UXP Version: 7.4.1

  • Photoshop Version: 25.9.0

Does anyone have an explanation for why batchPlay isn’t picking this up, or if there’s a specific permission/syntax I’m missing for runJavaScript in UXP?

You would also use this to execute an ExtendScript file. And the Adobe team did not want devs to mix those two together. So it does not work. Sadly, they do not distinguish between .jsx and .psjs

1 Like

Funny enough, I can get it to work with .jsx files using the following function:

JavaScript

async function runJSX(path) {
    const fs = require('uxp').storage.localFileSystem;
    const token = fs.createSessionToken(await fs.getEntryWithUrl("plugin-data:/" + path));
    
    return await action.batchPlay([
        {
            _obj: "AdobeScriptAutomation Scripts",
            javaScript: {
                _path: token,
                _kind: "local"
            },
            javaScriptMessage: "JSM",
            _options: {
                dialogOptions: "dontDisplay"
            }
        }
    ], {
        continueOnError: true
    });
};


But for some reason, it just won’t work with .psjs files. This feels completely nonsensical—why would the older format work while the modern one doesn’t?

Adobe restricts to run UXP scripts from UXP plugins.
Check out this thread: Panel with buttons to run psjs files

2 Likes