Copy link to clipboard
Copied
Hey, I'm making a script that will run automatically each time the user uses the Liquify Filter, and will repeat it if the layer has a mask and that mask is linked (and that mask is not selected).
I've made a working script so far (copying functions from forums and using the script listener, I'm a bit of noob when it comes to JS and photoshop scripting lol), but I don't know how to make a function that would return true if the layer and its mask are linked.
Ideally, I wouldn't want the script to execute if they aren't linked.
In the future I'd also like to make an array of all layers the active layer is linked to, and repeat the liquify on them and their masks (if linked) as well, but that's beyond the scope of my skills at the moment, obviously.
If you're interested in my hodgepodge of a code, here you go. It works, but it's not graceful to read.
function layerMaskIsSelected() {
s2t = stringIDToTypeID;
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('hasUserMask'));
r.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
if (executeActionGet(r).getBoolean(p)) {
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
(r = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
layerName = executeActionGet(r).getString(p);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('channelName'));
r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
channelName = executeActionGet(r).getString(p);
(r = new ActionReference()).putProperty(s2t('property'), p = s2t('alphaChannelOptions'));
r.putEnumerated(s2t("channel"), s2t("ordinal"), s2t("targetEnum"));
alphaChannel = executeActionGet(r).hasKey(p);
return (channelName.indexOf(layerName) == 0 && !alphaChannel);
}
}
function hasLayerMask () {
var m_Dsc01, m_Ref01;
m_Ref01 = new ActionReference();
m_Ref01.putEnumerated(stringIDToTypeID("layer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
m_Dsc01 = executeActionGet(m_Ref01);
return m_Dsc01.hasKey(charIDToTypeID("Usrs"));
};
if (hasLayerMask(app.activeDocument.activeLayer) && !layerMaskIsSelected(app.activeDocument.activeLayer)) {
var idslct = charIDToTypeID( "slct" );
var desc8 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idMsk = charIDToTypeID( "Msk " );
ref1.putEnumerated( idChnl, idChnl, idMsk );
desc8.putReference( idnull, ref1 );
var idMkVs = charIDToTypeID( "MkVs" );
desc8.putBoolean( idMkVs, false );
executeAction( idslct, desc8, DialogModes.NO );
var d = new ActionDescriptor();
d.putString(charIDToTypeID("LqMD"), app.preferencesFolder.fsName+"\\"+"Liquify Last Mesh.psp");
executeAction(charIDToTypeID("LqFy"), d, DialogModes.NO);
var idslct = charIDToTypeID( "slct" );
var desc9 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref2 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
ref2.putEnumerated( idChnl, idChnl, idRGB );
desc9.putReference( idnull, ref2 );
var idMkVs = charIDToTypeID( "MkVs" );
desc9.putBoolean( idMkVs, false );
executeAction( idslct, desc9, DialogModes.NO );
}
Any help will be greatly appreciated!
Try this (credit to r-bin):
/*
Get Linked Property of Layer Mask.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-function-that-detects-if-layer-and-mask-are-linked/td-p/14072122
Based on work by by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/collapse-single-group-of-layers/m-p/13642327
*/
#target photoshop
try {
var id = activeDocument.activeLayer.id;
var r = new ActionReference();
r.putProperty(stringIDToTyp
...
Copy link to clipboard
Copied
Try this (credit to r-bin):
/*
Get Linked Property of Layer Mask.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-function-that-detects-if-layer-and-mask-are-linked/td-p/14072122
Based on work by by r-bin
https://community.adobe.com/t5/photoshop-ecosystem-discussions/collapse-single-group-of-layers/m-p/13642327
*/
#target photoshop
try {
var id = activeDocument.activeLayer.id;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("userMaskLinked"));
r.putIdentifier(stringIDToTypeID("layer"), id);
var getStatus = executeActionGet(r).getBoolean(stringIDToTypeID("userMaskLinked"));
// returns boolean, true | false
// alert(getStatus?"Linked = True":"Linked = False");
if (getStatus === true) {
alert("Linked = True \r Do something!...");
} else {
alert("Linked = False \r Do nothing!");
}
} catch (e) {}
NOTE: The check is for a raster layer mask, not vector.
Copy link to clipboard
Copied
Works like a charm, thank you very much!
I edited it a little to turn it into a function that I can put inside the "if" condition:
function layerMaskIsLinked() {
var id = activeDocument.activeLayer.id;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("userMaskLinked"));
r.putIdentifier(stringIDToTypeID("layer"), id);
var getStatus = executeActionGet(r).getBoolean(stringIDToTypeID("userMaskLinked"));
return getStatus;
}
And the condition from above looks like this:
var currentLayer = app.activeDocument.activeLayer
if (hasLayerMask(currentLayer) && !layerMaskIsSelected(currentLayer) && layerMaskIsLinked(currentLayer)) {
Now I gotta figure out how to make an array of all layers this one is linked to and repeat the thing there. I'll hit my head against the problem for a bit before asking for help again though. Thanks again! ❤️