Search code examples
javascriptphotoshopphotoshop-script

How can I "Merge Visible" to a layer in a Photoshop script?


The activeDocument.mergeVisibleLayers(); command simply flattens the image to the Background layer.

I am looking for a way to merge all layers to a new layer which stays on top of all other layers, like the Layer->Merge Visible (Ctrl+Shift+E) Photoshop command.

Is that possible?


Solution

  • Not sure if this is the best solution but it worked for me:

    // Copy all visible layers to clipboard (true = merged)
    activeDocument.activeLayer.copy(true);
    // then paste them (creates a new layer)
    activeDocument.paste();