I used activeDocument.mergeVisibleLayers();
, but that's not what I want, because it excludes other layers. In Photoshop shortcuts, I used to use Ctrl + Shift + Alt + E. Does anyone know how to do this?
There should've been a boolean to tell PS if you want to flatten the layers or not, but as it often a case with DOM code, there's none. AM code for rescue!
var desc = new ActionDescriptor();
desc.putBoolean(charIDToTypeID('Dplc'), true); // true to merge to new, false to flatten
executeAction(charIDToTypeID('MrgV'), desc, DialogModes.NO);