Can i run javascript.jsx file using UXP button

I’m using this code to get a button to fire a JSX script that’s in the plugin folder inside a JSX folder

async function ScriptRun(jsxFile) {

   let pluginFolder = await fs.getPluginFolder()

   try {
      let jsxFileObject = await pluginFolder.getEntry(jsxFile);
      var filetoken = await fs.createSessionToken(jsxFileObject);
   } catch (e) {
      app.showAlert("Script does not exist");
   }
   return await batchPlay(
      [
         {
            "_obj": "AdobeScriptAutomation Scripts",
            "javaScript": {
               "_path": filetoken,
               "_kind": "local"
            },
            "javaScriptMessage": "JSM",
            "_isCommand": true,
            "_options": {
               "dialogOptions": "dontDisplay"
            }
         }
      ], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
   });
}

document.querySelector("#button").addEventListener("click", scriptSelector);

async function scriptSelector() {

   var script = "jsx/scriptName.js" // <--- point this to your script

   await ScriptRun(script)

}
3 Likes