Skip to main content
Known Participant
Apr 9, 2025 9:08 AM UTC
Answered

Function for Layer Mask > Reveal Selection?

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.

 

 

Stephen Marsh
Stephen MarshCorrect answer
Community Expert
Apr 9, 2025 9:54 AM UTC

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

 

3 replies

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
Apr 9, 2025 9:54 AM UTC

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

 

Translate
HeyoThereAuthor
Known Participant
Apr 9, 2025 7:33 PM UTC

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

Translate
Stephen Marsh
Community Expert
Community Expert
Apr 9, 2025 9:08 PM UTC
quote

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


By @HeyoThere


You're welcome!

Translate