Fnykis
6/30/2017 - 8:01 AM

Select mask of requested layer

Select mask of requested layer

function selectMask(LayerName){ // Input ie. activeDocument.activeLayer.name
	try{
		
		var desc = new ActionDescriptor();
		var ref = new ActionReference();
		ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Msk ') );
		ref.putName( charIDToTypeID('Lyr '), LayerName );
		desc.putReference( charIDToTypeID('null'), ref );
		desc.putBoolean( charIDToTypeID('MkVs'), true );
		executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );

		// =======================================================
		var id1083 = charIDToTypeID( "setd" );
		var desc238 = new ActionDescriptor();
		var id1084 = charIDToTypeID( "null" );
		var ref161 = new ActionReference();
		var id1085 = charIDToTypeID( "Chnl" );
		var id1086 = charIDToTypeID( "fsel" );
		ref161.putProperty( id1085, id1086 );
		desc238.putReference( id1084, ref161 );
		var id1087 = charIDToTypeID( "T   " );
		var ref162 = new ActionReference();
		var id1088 = charIDToTypeID( "Chnl" );
		var id1089 = charIDToTypeID( "Ordn" );
		var id1090 = charIDToTypeID( "Trgt" );
		ref162.putEnumerated( id1088, id1089, id1090 );
		desc238.putReference( id1087, ref162 );
		executeAction( id1083, desc238, DialogModes.NO );
		
		// Select the RGB channel instead of the mask channel
		var id248 = charIDToTypeID( "slct" );
		var desc48 = new ActionDescriptor();
		var id249 = charIDToTypeID( "null" );
		var ref36 = new ActionReference();
		var id250 = charIDToTypeID( "Chnl" );
		var id251 = charIDToTypeID( "Chnl" );
		var id252 = charIDToTypeID( "RGB " );
		ref36.putEnumerated( id250, id251, id252 );
		desc48.putReference( id249, ref36 );
		var id253 = charIDToTypeID( "MkVs" );
		desc48.putBoolean( id253, false );
		executeAction( id248, desc48, DialogModes.NO );
		
	}catch(e){
		// No mask on the layer
		activeDocument.selection.deselect();
	}
}