How to Select Current Layer Content Without a Pop-Up in Photoshop Script?
Hello everyone,
I'm working on a Photoshop script and need to select the content of the current active layer without triggering any dialog boxes or pop-ups.
I've tried executeAction( idsetd, desc, DialogModes.NO ), but this often brings up a "feather selection" dialog. I'm looking for a way to achieve a direct selection of the layer's pixels, similar to Ctrl/Cmd + click on the layer thumbnail, but entirely through scripting and without any user interaction required.
function loadLayerTransparencySelection(layerName) {
var doc = app.activeDocument;
var targetLayer = null;
for (var i = 0; i < doc.layers.length; i++) {
if (doc.layers[i].name === layerName) {
targetLayer = doc.layers[i];
break;
}
}
if (targetLayer) {
doc.activeLayer = targetLayer;
var idsetd = charIDToTypeID( "setd" );
var desc = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref.putProperty( idChnl, idfsel );
desc.putReference( idnull, ref );
var idTo = charIDToTypeID( "To " );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idTrsp = charIDToTypeID( "Trsp" );
ref1.putEnumerated( idChnl, idChnl, idTrsp );
desc.putReference( idTo, ref1 );
executeAction( idsetd, desc, DialogModes.NO );
} else {
alert("no: '" + layerName );
}
}
loadLayerTransparencySelection(app.activeDocument.activeLayer.name);
Is there a specific method or a sequence of commands in the Photoshop scripting API that can accomplish this silently?
Any help or pointers would be greatly appreciated!
Thanks in advance.
