Layer Mask Preview Toggle Script PS2021
On this forum, I found a function by Michael Hale that selects and previews a layer mask. I edited the function to create another function that turns the mask preview off. When the function runs the mask preview is on/off depending on the alert call.
Next, I try to create a mask preview toggle through an if statement to turn the mask preview on/off.
if the mask preview is on then run the maskPreviewOff() function.
else if the mask preview is off then run the maskPrevicwOn() function
So far I have not been able to make the mask toggle work and I am not sure if it is possible.
Can someone please look at the code and advise if the mask preview toggle can be done vis script?
//alert(maskPreviewOff()); // returns true
//alert(maskPreviewOn()); // returns false
if(maskPreviewOff() == true) {
alert("The mask is off");
} else if (maskPreviewOn() == true){
alert("The mask is on");
}
else{}
///////////////////////////
// FUNTIONS
///////////////////////////
function maskPreviewOn(){
var rc = false;
try {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), true );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
rc = true;
} catch (e) {
if (!e.toString().match(/Select.+is not currently available/)) {
throw e;
}
}
return rc;
}
function maskPreviewOff(){
var rc = true;
try {
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Msk " ) );
desc.putReference( charIDToTypeID( "null" ), ref );
desc.putBoolean( charIDToTypeID( "MkVs" ), false );
executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );
rc = false;
} catch (e) {
if (!e.toString().match(/Select.+is not currently available/)) {
throw e;
}
}
return rc;
}
