Skip to main content
Participating Frequently
July 31, 2025
Answered

How to Select Current Layer Content Without a Pop-Up in Photoshop Script?

  • July 31, 2025
  • 2 replies
  • 244 views

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.

Correct answer Stephen Marsh

Does this do what you are after?

 

loadLayerTrans();

function loadLayerTrans() {
        var idset = stringIDToTypeID("set");
        var desc323 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref75 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idselection = stringIDToTypeID("selection");
        ref75.putProperty(idchannel, idselection);
        desc323.putReference(idnull, ref75);
        var idto = stringIDToTypeID("to");
        var ref76 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idchannel = stringIDToTypeID("channel");
        var idtransparencyEnum = stringIDToTypeID("transparencyEnum");
        ref76.putEnumerated(idchannel, idchannel, idtransparencyEnum);
        desc323.putReference(idto, ref76);
        executeAction(idset, desc323, DialogModes.NO);
}

2 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
July 31, 2025

Does this do what you are after?

 

loadLayerTrans();

function loadLayerTrans() {
        var idset = stringIDToTypeID("set");
        var desc323 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref75 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idselection = stringIDToTypeID("selection");
        ref75.putProperty(idchannel, idselection);
        desc323.putReference(idnull, ref75);
        var idto = stringIDToTypeID("to");
        var ref76 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idchannel = stringIDToTypeID("channel");
        var idtransparencyEnum = stringIDToTypeID("transparencyEnum");
        ref76.putEnumerated(idchannel, idchannel, idtransparencyEnum);
        desc323.putReference(idto, ref76);
        executeAction(idset, desc323, DialogModes.NO);
}
kj_4500Author
Participating Frequently
July 31, 2025

Yes!! Thanks so much!!!

Stephen Marsh
Community Expert
Community Expert
July 31, 2025

You're welcome!

kj_4500Author
Participating Frequently
July 31, 2025

I made a mistake. It was the "Selection Area" window that popped up.