Execute a script via a button

OK, I just updated it again. I missed the last line and the closing bracket when I copied it last time… oops.

//Use same ID in HTML doc
document.getElementById("yourButtonID").addEventListener("click", async function (){
await playAction("Your Action Set","Your Action");
});

async function playAction(setName,actionName){

let setFound=false;    
let actionFound=false;    
 
  const actionSets = require('photoshop').app.actionTree;
    
 // check for action set name to exist    
  for (let i=0; i<actionSets.length; i++){
      if (actionSets[i].name==setName){var setToPlay=actionSets[i]; setFound=true;}
  }
  
 //check for action name to exist    
 if(setFound==true){
    for (let i=0; i<setToPlay.actions.length; i++){
    if (setToPlay.actions[i].name==actionName){var actionToPlay=setToPlay.actions[i]; actionFound=true;}
    }
}    

 //play if action set/action both exist    
  if(setFound==true&&actionFound==true){await actionToPlay.play();}    
    
}