# Merge visible using \`batchPlay\`

**URL:** <https://forums.creativeclouddeveloper.com/t/merge-visible-using-batchplay/2539>\
**Category:** UXP Plugin API\
**Created:** [February 18, 2021, 7:50pm UTC](https://forums.creativeclouddeveloper.com/t/merge-visible-using-batchplay/2539 "2021-02-18T19:50:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OrYair](https://avatars.discourse-cdn.com/v4/letter/o/d26b3c/32.png) [@OrYair](https://forums.creativeclouddeveloper.com/u/OrYair)\
**Post date:** [February 18, 2021, 7:50pm UTC](https://forums.creativeclouddeveloper.com/t/merge-visible-using-batchplay/2539/1 "2021-02-18T19:50:48Z")

</div>

Hello,  
I have the following funciton in JSX code:

```auto
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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/6/69b7b2b01d8adc9a12ebc9b209070a4c786c547a.png)

---

<div class="post-metadata">

**Author:** ![ddbell](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ddbell/32/1030_2.png) [@ddbell](https://forums.creativeclouddeveloper.com/u/ddbell)\
**Post date:** [February 18, 2021, 8:25pm UTC](https://forums.creativeclouddeveloper.com/t/merge-visible-using-batchplay/2539/2 "2021-02-18T20:25:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pierre\_G](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pierre_g/32/971_2.png) [@Pierre\_G](https://forums.creativeclouddeveloper.com/u/Pierre_G)\
**Post date:** [February 18, 2021, 9:40pm UTC](https://forums.creativeclouddeveloper.com/t/merge-visible-using-batchplay/2539/3 "2021-02-18T21:40:42Z")

</div>

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"
});
```
