Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


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

Explorer ,
Dec 28, 2018 Dec 28, 2018

Copy link to clipboard

Copied

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

};

TOPICS
Actions and scripting

Views

1.9K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Dec 29, 2018 Dec 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.

Likes

Translate

Translate
Adobe Community Professional ,
Dec 28, 2018 Dec 28, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 28, 2018 Dec 28, 2018

Copy link to clipboard

Copied

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

};

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 18, 2021 May 18, 2021

Copy link to clipboard

Copied

LATEST

thank you,your answer save my life!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 29, 2018 Dec 29, 2018

Copy link to clipboard

Copied

I tried your both scripts on new document with 'white' mask created from selection of document bounds and in both cases I had the same result, so a layer mask(s) (if filled whole document, with any opacity & fill level) got deleted with no problem.

I don't know why you had that warning. By the way I aslo removed from end of your first code mistakenly put last 6 lines.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 30, 2018 Dec 30, 2018

Copy link to clipboard

Copied

Probably you've checked "Don't show again".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 30, 2018 Dec 30, 2018

Copy link to clipboard

Copied

I guess so, but why didn't you did the same in no time? 🙂

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 30, 2018 Dec 30, 2018

Copy link to clipboard

Copied

Ah, it's just because I think this warning message is useful in my workflow in Photoshop. This is the way how I check when a mask is blank or not.
With this script now, I hope my workflow will be simplified...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines