Skip to content

Photoshop select layers

March 21, 2014

This is just a small function for Photoshop’s JavaScript engine (ExtendScript) that will select all of the layers in a folder.  It’s nothing big, but I wasn’t able to find any straight forward method besides using the internal Photoshop language.

function SelectFolderPixels(folder)
{ 
    var idsetd = charIDToTypeID( "setd" );
    var desc28 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref27 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idfsel = charIDToTypeID( "fsel" );
        ref27.putProperty( idChnl, idfsel );
    desc28.putReference( idnull, ref27 );
    var idT = charIDToTypeID( "T   " );
        var ref28 = new ActionReference();
        var idChnl = charIDToTypeID( "Chnl" );
        var idChnl = charIDToTypeID( "Chnl" );
        var idTrsp = charIDToTypeID( "Trsp" );
        ref28.putEnumerated( idChnl, idChnl, idTrsp );
        var idLyr = charIDToTypeID( "Lyr " );
        ref28.putName( idLyr, folder.layers[0].name );
    desc28.putReference( idT, ref28 );
    executeAction( idsetd, desc28, DialogModes.NO );

    if (folder.layers.length > 1)
    {

        for (var i = 1; i < folder.layers.length; i++)
        {
            var idAdd = charIDToTypeID( "Add " );
            var desc35 = new ActionDescriptor();
            var idnull = charIDToTypeID( "null" );
                var ref37 = new ActionReference();
                var idChnl = charIDToTypeID( "Chnl" );
                var idChnl = charIDToTypeID( "Chnl" );
                var idTrsp = charIDToTypeID( "Trsp" );
                ref37.putEnumerated( idChnl, idChnl, idTrsp );
                var idLyr = charIDToTypeID( "Lyr " );
                ref37.putName( idLyr, folder.layers[i].name );
            desc35.putReference( idnull, ref37 );
            var idT = charIDToTypeID( "T   " );
                var ref38 = new ActionReference();
                var idChnl = charIDToTypeID( "Chnl" );
                var idfsel = charIDToTypeID( "fsel" );
                ref38.putProperty( idChnl, idfsel );
            desc35.putReference( idT, ref38 );
            executeAction( idAdd, desc35, DialogModes.NO );
        }
    }
}
Advertisements
Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: