Skip to main content
Known Participant
January 13, 2022
Answered

"Apply All Layer Masks"

  • January 13, 2022
  • 3 replies
  • 909 views

Hello,

 

I have several files with hundreds of layers and many of those layers have masks. Is there script to "Apply Layer Masks"; much like the "Rasterize All Layers"? I'm looking to reduce file sizes on old projects.

 

Thanks for your time,

J

Correct answer c.pfaffenbichler

File > Scripts > Flatten All Masks

3 replies

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
January 13, 2022

File > Scripts > Flatten All Masks

Stephen Marsh
Community Expert
Community Expert
January 13, 2022

Hah, I'd forgotten about that one!

Stephen Marsh
Community Expert
Community Expert
January 13, 2022

Try this script. Layer sets and their contents are not processed, this script is intended for "flat" layer structures

 

/*
Apply Layer Mask To All Layers.jsx
v1.0 - Stephen Marsh, 13th January 2022
https://community.adobe.com/t5/photoshop-ecosystem-discussions/quot-apply-all-layer-masks-quot/m-p/12655017
Note: Layer sets and their contents are not processed, this script is intended for "flat" layer structures
*/

#target photoshop

function main() {
  
    app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

    // Loop forward over top level layers
    // for (var i = 0; i < app.activeDocument.layers.length; i++) {
    // Loop backward over top level layers
    for (var i = app.activeDocument.layers.length - 1; i >= 0; i--) {
        try {
            app.activeDocument.activeLayer = app.activeDocument.layers[i];
            applyLayerMask();
        } catch (e) { }
    }

    function applyLayerMask() {
        var iddelete = stringIDToTypeID("delete");
        var desc352 = new ActionDescriptor();   
        var idnull = stringIDToTypeID("null");
        var ref64 = new ActionReference();
        var idchannel = stringIDToTypeID("channel");
        var idchannel = stringIDToTypeID("channel");
        var idmask = stringIDToTypeID("mask");
        ref64.putEnumerated(idchannel, idchannel, idmask);
        desc352.putReference(idnull, ref64);
        var idapply = stringIDToTypeID("apply");
        desc352.putBoolean(idapply, true);
        executeAction(iddelete, desc352, DialogModes.NO);
    }
}
app.activeDocument.suspendHistory("Apply Layer Mask To All Layers.jsx", "main()");

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

Kukurykus
Legend
January 13, 2022

What's the structures of layers in the document, like for ex. no layer sets?