Batch play - play action firing on plugin reload but not when button is clicked

I’m attempting to map my actions to buttons in my UXP plugin. When setting the button to run the patch play function on-click it doesn’t work. However, when I reload the plugin it registers a click and runs the function. I’m brand new at UXP and only started learning Javascript to create a plugin for my company. Anyone that can help with a more comprehensive explanation would be my hero.

document
.getElementById("play-action")
.addEventListener("click", playAction('Wine Glass LASER'));


async function playAction(actionName){
const batchPlay = require("photoshop").action.batchPlay;
console.log("playing?")
const result = await batchPlay(
[
   {
      _obj: "play",
      _target: [
         {
            _ref: "action",
            _name: actionName
         },
         {
            _ref: "actionSet",
            _name: "Mockup Maker"
         }
      ],
      _options: {
         dialogOptions: "dontDisplay"
      }
   }
],{
   synchronousExecution: false,
   modalBehavior: "wait"
});
}

No JS expert either, but I think you might need different syntax to pass a variable to a “click” function:

.addEventListener('click', function() {playAction('Wine Glass LASER');});

Change to:
.addEventListener("click", function() {playAction('Wine Glass LASER')});

Edit
While replied on phone, you got your answer already :slight_smile:

Thank you both! One incredibly frustrating issue down. 500 to go!

If you’re OK w/ modern JS syntax and want something shorter, this’ll do the same thing:

.addEventListener("click", () => playAction("Wine Glass LASER"));
1 Like

I’m far too new to have any preference. I sincerely appreciate the help. We have a team of 8 working in photoshop daily and the time we all waste on repetitive tasks is crazy. The time it’s been taking me to learn Java and UXP will be saved in man hours in one week!

1 Like