Merge visible using `batchPlay`

Hello,
I have the following funciton in JSX code:

mergeVisible()

function string2ID(str) {return app.stringIDToTypeID(str);}

function mergeVisible()
{
    var desc = new ActionDescriptor();
    desc.putBoolean(string2ID("duplicate"), true);
    executeAction(string2ID("mergeVisible"), desc, DialogModes.NO);
}

I want to run in using batchPlay.

I ran the code while listening with the Alchemist plug-in, but the obtained output outputs an error when I try to run it.

You will need to record the merge visible command by performing it in the Photoshop menu (or keyboard shortcut), not running from a JSX file.

Hello, you might want to try this:

const batchPlay = require("photoshop").action.batchPlay;

// Merge Visible layers on a new layer
await batchPlay(
[
   {
      "_obj": "mergeVisible",
      "duplicate": true,
      "_isCommand": true,
      "_options": {
         "dialogOptions": "dontDisplay"
      }
   }
],{
   "synchronousExecution": false,
   "modalBehavior": "fail"
});
1 Like