Last active
June 6, 2024 01:24
-
-
Save joonaspaakko/1add5c6a905216740c9c922a657636e1 to your computer and use it in GitHub Desktop.
Select Child Layers.jsx Photoshop Script - Selects the first level of layers inside the currently active group.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://gist.github.com/joonaspaakko/1add5c6a905216740c9c922a657636e1 | |
#target photoshop | |
if ( app.activeDocument.activeLayer.typename == 'LayerSet' ) { | |
app.activeDocument.suspendHistory( "Select Child Layers.jsx", "init();" ); | |
} | |
function init() { | |
var doc = app.activeDocument; | |
var sourceGroup = app.activeDocument.activeLayer; | |
// Make a temp group with a temp layer inside it: | |
// [Parent group] | |
// - [TEMP GROUP] | |
// - - [TEMP LAYER] | |
var tempGroup = sourceGroup.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 = sourceGroup.layers.length - 1; | |
for ( var i = 0; i < children_length; i++ ) { | |
var lastLayer = sourceGroup.layers[ sourceGroup.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