Thi is my code to find selected Top group layers (layeSets), relative position.
I am using it to avoid selecting document active layer using "getByName".
The number can be used at:
app.activeDocument.activeLayer = app.activeDocument.layerSets[2];
I hope it is usefull and correct, since i have almost none exprerience at scripting
( There are similar posts based on ActionManager I think, but I this code is easier to use)
var sel_name = app.activeDocument.activeLayer.name;
var c = -1;
for(var i = 0; i < app.activeDocument.layerSets.length; i++) {
if(activeDocument.layerSets[i].typename == "LayerSet")
{c++}
if (app.activeDocument.layerSets[c].name == sel_name) {
var layerset_index = i;
}
alert(layerset_index);