Search code examples
javascriptphotoshopphotoshop-script

Select visible pixels in a layer


I'm writing a Photoshop script using JavaScript where I need to select all visible pixels in a layer to apply an effect on another layer.

The selection I need is the same as when you control+click on a layer thumbnail.

How can I do this?


Solution

  • I think what you are after is this:

    var id1268 = charIDToTypeID( "setd" );
    var desc307 = new ActionDescriptor();
    var id1269 = charIDToTypeID( "null" );
    var ref257 = new ActionReference();
    var id1270 = charIDToTypeID( "Chnl" );
    var id1271 = charIDToTypeID( "fsel" );
    ref257.putProperty( id1270, id1271 );
    desc307.putReference( id1269, ref257 );
    var id1272 = charIDToTypeID( "T   " );
    var ref258 = new ActionReference();
    var id1273 = charIDToTypeID( "Chnl" );
    var id1274 = charIDToTypeID( "Chnl" );
    var id1275 = charIDToTypeID( "Trsp" );
    ref258.putEnumerated( id1273, id1274, id1275 );
    desc307.putReference( id1272, ref258 );
    executeAction( id1268, desc307, DialogModes.NO )
    

    Which will make a selection of all current pixels in the current layer (like pressing CTRL)