I’m trying to see if a layer mask is active or not - that is to say, whether the currently active thing we’re editing is a layer mask or not (rather than whether a mask is enabled or present).
So far I’ve got this, which looks at app.activeDocument.activeChannels, which returns an error if a mask is active, but that seems hackish, and I’m hoping to get on the app store, so I’m wondering if there’s a better way that I’ve missed!
async function isMaskActive() {
try {
const app = require("photoshop").app;
// This will throw an error if a mask is active
app.activeDocument.activeChannels;
return false;
} catch (error) {
// If we get the "Unknown or unsupported active channels" error,
// it means we're in a mask
if (error.message.includes("Unknown or unsupported active channels")) {
return true;
}
// For any other error, we should probably rethrow it
throw error;
}
}