Skip to content

Instantly share code, notes, and snippets.

@hilukasz
Last active July 12, 2023 15:52
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save hilukasz/03b17ee78414aadff995 to your computer and use it in GitHub Desktop.
Save hilukasz/03b17ee78414aadff995 to your computer and use it in GitHub Desktop.
get array of selected layers in photoshop via extendscript
var docRef = app.activeDocument;
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
function newGroupFromLayers(doc) {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass( sTID('layerSection') );
desc.putReference( cTID('null'), ref );
var lref = new ActionReference();
lref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc.putReference( cTID('From'), lref);
executeAction( cTID('Mk '), desc, DialogModes.NO );
};
function undo() {
executeAction(cTID("undo", undefined, DialogModes.NO));
};
function getSelectedLayers(doc) {
var selLayers = [];
newGroupFromLayers();
var group = doc.activeLayer;
var layers = group.layers;
for (var i = 0; i < layers.length; i++) {
selLayers.push(layers[i]);
}
undo();
return selLayers;
};
var selectedLayers = getSelectedLayers(app.activeDocument);
for( i = 0; i < selectedLayers.length; i++) {
selectedLayers[i].selected = true;
docRef.activeLayer = selectedLayers[i];
alert(docRef.activeLayer.name)
}
@schroef
Copy link

schroef commented Jul 12, 2023

@no
I think this resize all items at once and the undoes the grouping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment