I have a script to loop through a document and check on every layer if there is a blank layer mask, and then delete that layer mask.
I'm not sure if there is a best approach to check if a layer mask is blank than getting a selection and inverting it.
After inverting, if there is no selection, Photoshop pops up a warning message stating "No pixels are selected."
How to avoid this message without check "Don't show again"?
for ( var a =0; a<activeDocument.artLayers.length; a++ ){
activeDocument.activeLayer = activeDocument.artLayers[a];
checkLayerMask();
};
function checkLayerMask() {
// has layer mask
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
var desc = executeActionGet(ref);
var hasLayerMask = desc.hasKey(charIDToTypeID("UsrM")); // bool
if (hasLayerMask) {
// make layer mask active
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
// get selection from layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "T " ), ref );
executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );
// invert selection
activeDocument.selection.invert();
try { activeDocument.selection.bounds}
catch(e) {
// delete active layer mask
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
desc.putReference( charIDToTypeID( "null" ), ref );
executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );
};
}
app.activeDocument.selection.deselect();
};
AM command with DialogModes
set to NO
won't produce this message:
executeAction(charIDToTypeID('Invs'), undefined, DialogModes.NO);