Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Select Sibling Layers.jsx Photoshop Script - Selects the sibling layers.
//https://gist.github.com/joonaspaakko/d4449fd5ef211df7850cab748bf9b8f6
#target photoshop
if ( app.activeDocument.activeLayer.parent !== app.activeDocument ) {
app.activeDocument.suspendHistory( "Select Sibling Layers.jsx", "init();" );
}
function init() {
var doc = app.activeDocument;
var parent = app.activeDocument.activeLayer.parent;
// Make a temp group with a temp layer inside it:
// [Parent group]
// - [TEMP GROUP]
// - - [TEMP LAYER]
var tempGroup = parent.layerSets.add();
tempGroup.name = 'TEMP GROUP';
var tempLayer = tempGroup.artLayers.add();
tempLayer.name = 'TEMP LAYER';
// Loop through all direct child element and move the last layer below 'TEMP LAYER'
var children_length = parent.layers.length - 1;
for ( var i = 0; i < children_length; i++ ) {
var lastLayer = parent.layers[ parent.layers.length-1 ];
lastLayer.move( tempGroup.layers[0], ElementPlacement.PLACEAFTER );
}
// Get rid of TEMP LAYER
tempLayer.remove();
// Get rid of TEMP GROUP by ungrouping it, which also happens to select its children.
doc.activeLayer = tempGroup;
// Ungroup tempGroup
// =======================================================
var idungroupLayersEvent = stringIDToTypeID( "ungroupLayersEvent" );
var desc702 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref427 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref427.putEnumerated( idLyr, idOrdn, idTrgt );
desc702.putReference( idnull, ref427 );
executeAction( idungroupLayersEvent, desc702, DialogModes.NO );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment