Skip to main content
danielsian.com
Inspiring
December 29, 2018
Answered

How to suppress pop-up message in Photoshop script “No pixels are selected.”

  • December 29, 2018
  • 1 reply
  • 4195 views

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;

     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();

};

executeAction( charIDToTypeID( "Dlt " ), desc, DialogModes.NO );

};

}

app.activeDocument.selection.deselect();

};

This topic has been closed for replies.
Correct answer r-bin

Your code in the first post contains errors at the end.
However, if you fix it and insert it at the very beginning

app.displayDialogs = DialogModes.NO;


then you get what you want.

1 reply

Kukurykus
Legend
December 29, 2018

I don't know how to create blank selection, but I'm experiencing it sometimes and I think the best way to check it is blank, is to make path from selection. If that selection is not invisible then path can be created that you may check whether it exists.

danielsian.com
Inspiring
December 29, 2018

I think I was not clear in my question, sorry about that.
My understanding about blank mask is a white mask, where the layer is 100% opaque.
The intention deleting white masks is to keep the document tidy without unnecessary masks.

I think I got a solution for my problem getting a selection using 'Select and Mask' tool. So I can check if the mask is 100% black when there is no selection.

This is the revised code:

for ( var a =0; a<activeDocument.layers.length; a++ ){

     activeDocument.activeLayer = activeDocument.layers;

     alert(activeDocument.layers.name)

     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 );

          // invert layer mask

          var idInvr = charIDToTypeID( "Invr" );

          executeAction( idInvr, undefined, DialogModes.NO );

          // get selection from layer mask through 'Select and Mask'

          var desc = new ActionDescriptor();

          executeAction( stringIDToTypeID( "smartBrushWorkspace" ), desc, DialogModes.NO );

          try {

               activeDocument.selection.bounds;

               app.activeDocument.selection.deselect();

               // invert layer mask

               var idInvr = charIDToTypeID( "Invr" );

               executeAction( idInvr, undefined, DialogModes.NO );

          }

          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();

};

r-binCorrect answer
Legend
December 29, 2018

Your code in the first post contains errors at the end.
However, if you fix it and insert it at the very beginning

app.displayDialogs = DialogModes.NO;


then you get what you want.