Context
I’m transitioning a large code base of Extend Script code into a UXP environment. Unfortunately UXP is very much still under development, and a number of document operations are not yet functional. For example, layer comp CRUD behavior, but there are likely others. As a workaround, I’ve built the user interface in UXP, and am attempting to continue using Extend Script for the document operations. I am more than happy to depreciate the Extend Script code as UXP’s ambitions are better supported.
The last, and perhaps final, milestone towards a minimum viable product involves using Batch Play to call a JSX file residing within the developer plugin folder (to avoid user input). It was once functioning but is no longer.
Related Code
let batchPlay = require("photoshop").action.batchPlay;
let filesystem = require("uxp").storage.localFileSystem;
export async function runPluginJsx(filename) {
let folder = await filesystem.getDataFolder()
const filepath = filename + ".jsx";
let jsxFileObject = await folder.getEntry(filepath);
let filetoken = await filesystem.createSessionToken(jsxFileObject);
let command = [
{
"_obj":"AdobeScriptAutomation Scripts",
"javaScript":{
"_kind":"local",
"_path": filetoken,
},
"javaScriptMessage": "JSM",
"_isCommand": true,
"_options": {
"dialogOptions": "dontDisplay"
}
}
];
console.log("before") // prints
let result = await batchPlay(command, {
"synchronousExecution": false,
"modalBehavior": "fail"
});
console.log("after") // does not print
console.log(result) // does not print
return result
}
If I remove the await
call for result
(an error handling bug?), then I am able to see the promise is rejected for the following reason:
Error: Event: AdobeScriptAutomation Scripts may modify the state of Photoshop. Such events are only allowed from inside a modal scope
If a modal is required, can someone please point me towards a code sample that might help?