Hi,
If I am understand your question correctly, you want to duplicate multiple layers all together. If thsi is the case, then you need to select the layer each time before running the duplicateLayer method. Below is the snippet that will duplicate all layers in the active document.
function duplicateLayer() {
var actionString = "/version 3" +
"/name [ 5" +
" 5365742031" +
"]" +
"/isOpen 1" +
"/actionCount 1" +
"/action-1 {" +
" /name [ 15" +
" 4475706c6963617465204c61796572" +
" ]" +
" /keyIndex 0" +
" /colorIndex 0" +
" /isOpen 1" +
" /eventCount 1" +
" /event-1 {" +
" /useRulersIn1stQuadrant 0" +
" /internalName (ai_plugin_Layer)" +
" /localizedName [ 6" +
" 53686f773a20" +
" ]" +
" /isOpen 1" +
" /isOn 1" +
" /hasDialog 0" +
" /parameterCount 2" +
" /parameter-1 {" +
" /key 1836411236" +
" /showInPalette 4294967295" +
" /type (integer)" +
" /value 1" +
" }" +
" /parameter-2 {" +
" /key 1851878757" +
" /showInPalette 4294967295" +
" /type (ustring)" +
" /value [ 19" +
" 4475706c69636174652053656c656374696f6e" +
" ]" +
" }" +
" }" +
"}" +
"";
var tmp = File(Folder.desktop + "/Set 1.aia");
tmp.open('w');
tmp.write(actionString);
tmp.close();
app.loadAction(tmp);
app.doScript("Duplicate Layer", "Set 1", false);
app.unloadAction("Set 1", "");
tmp.remove();
}
var docRef = app.activeDocument
var _layers = docRef.layers;
app.executeMenuCommand('deselectall');
for (var l = 0; l < _layers.length; l++) {
_layers[l].pageItems[0].selected = true;;
duplicateLayer();
app.executeMenuCommand('deselectall');
}