Skip to main content
Known Participant
April 9, 2025
Answered

Function for Layer Mask > Reveal Selection?

  • April 9, 2025
  • 1 reply
  • 539 views

I'm making a script in which in the middle of it I need to apply a mask on the current selection, I'm not sure if I'm not knowing how to search for it but I just couldn't find an answer, so I thought I should ask it here. Is it possible to create a function that pretty much does the same as if I had an active selection and I applied a mask to it, using the button on the picture. Or to be more precise the Photoshop Keyboard Shortcuts on the Layer Mask Section calls it "Reveal Selection". So basically this:

 

So basically as in the images a function that would mask the selected area.

 

 

Correct answer Stephen Marsh

Is this for the new UXP framework or legacy ExtendScript? If ES, you'll need to use Action Manager (AM) code, not DOM code:

 

maskSelection("revealSelection"); // "revealSelection" or "hideSelection"

function maskSelection(maskParameter) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    descriptor.putClass(s2t("new"), s2t("channel"));
    reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
    descriptor.putReference(s2t("at"), reference);
    descriptor.putEnumerated(s2t("using"), s2t("userMaskEnabled"), s2t(maskParameter));
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

 

1 reply

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 9, 2025

Is this for the new UXP framework or legacy ExtendScript? If ES, you'll need to use Action Manager (AM) code, not DOM code:

 

maskSelection("revealSelection"); // "revealSelection" or "hideSelection"

function maskSelection(maskParameter) {
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    descriptor.putClass(s2t("new"), s2t("channel"));
    reference.putEnumerated(s2t("channel"), s2t("channel"), s2t("mask"));
    descriptor.putReference(s2t("at"), reference);
    descriptor.putEnumerated(s2t("using"), s2t("userMaskEnabled"), s2t(maskParameter));
    executeAction(s2t("make"), descriptor, DialogModes.NO);
}

 

HeyoThereAuthor
Known Participant
April 9, 2025

Thank you!! This is going to help me a lot!

Stephen Marsh
Community Expert
Community Expert
April 9, 2025
quote

Thank you!! This is going to help me a lot!


By @HeyoThere


You're welcome!