check if layer has layer mask

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

imreNicastro
Posts: 2
Joined: Fri Nov 29, 2024 5:37 pm

check if layer has layer mask

Post by imreNicastro »

Hi - i m learning javascript and trying to create a little script that would help me automate how I export files from Phothoshop.
Atm I am stuck on one aspect :
I want to loop through all layers in my active doc and check if a layer mask is applied.

I have been through the photoshop documentation, but i can't not find infos regarding layer masks in Ps in javascript.

This is the little bit of code i have at the momemt just to check if there is layer applied on a selected layer

var activeDoc = app.activeDocument;
var selectedLayer = doc.activeLayer;

if (selectedLayer.hasMask){
alert(selectedLayer.name + " has a mask.")
}
else {
alert(selectedLayer.name + " has no mask.")
}

This script returns "has no mask" - but my selected layer does have a layer mask applied.
Thank for the help!

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

User avatar
Kukurykus
Posts: 529
Joined: Mon Jul 25, 2016 12:36 pm

Re: check if layer has layer mask

Post by Kukurykus »

Code: Select all

sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('layer'), sTT('ordinal'), sTT('targetEnum'))
alert(executeActionGet(ref).getBoolean(sTT('hasUserMask')))
imreNicastro
Posts: 2
Joined: Fri Nov 29, 2024 5:37 pm

Re: check if layer has layer mask

Post by imreNicastro »

It worked! Thanks :)