(Again) Create Layer on top of every other layer through pure batchPlay

You can use this code to warp all your code under one single history state.

https://forums.creativeclouddeveloper.com/t/confused-about-suspend-history-usage/4855/5

const app = require("photoshop").app
const ExecuteAsModal = require("photoshop").core.executeAsModal

document.getElementById("btn").addEventListener("click", async function () {
  await ExecuteAsModal(functionName);
});

async function functionName(executionContext) {
  let hostControl = executionContext.hostControl;
  // let documentID = await getTargetDocument();

  let suspensionID = await hostControl.suspendHistory({
    documentID: app.activeDocument?.id,
    name: "History name",
  });


  // your functions
// batchPlay
//batchPlay 
// ……

  await hostControl.resumeHistory(suspensionID);
}

Edit to add the missing variables :sweat_smile: