Mask (scriptinglistener code):
// =======================================================
var idset = stringIDToTypeID( "set" );
var desc363 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref87 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
var idordinal = stringIDToTypeID( "ordinal" );
var idtargetEnum = stringIDToTypeID( "targetEnum" );
ref87.putEnumerated( idchannel, idordinal, idtargetEnum );
desc363.putReference( idnull, ref87 );
var idto = stringIDToTypeID( "to" );
var desc364 = new ActionDescriptor();
var idcolorIndicates = stringIDToTypeID( "colorIndicates" );
var idmaskIndicator = stringIDToTypeID( "maskIndicator" );
var idmaskedAreas = stringIDToTypeID( "maskedAreas" );
desc364.putEnumerated( idcolorIndicates, idmaskIndicator, idmaskedAreas );
var idchannel = stringIDToTypeID( "channel" );
desc363.putObject( idto, idchannel, desc364 );
executeAction( idset, desc363, DialogModes.NO );
Selected (scriptinglistener code):
// =======================================================
var idset = stringIDToTypeID( "set" );
var desc367 = new ActionDescriptor();
var idnull = stringIDToTypeID( "null" );
var ref89 = new ActionReference();
var idchannel = stringIDToTypeID( "channel" );
var idordinal = stringIDToTypeID( "ordinal" );
var idtargetEnum = stringIDToTypeID( "targetEnum" );
ref89.putEnumerated( idchannel, idordinal, idtargetEnum );
desc367.putReference( idnull, ref89 );
var idto = stringIDToTypeID( "to" );
var desc368 = new ActionDescriptor();
var idcolorIndicates = stringIDToTypeID( "colorIndicates" );
var idmaskIndicator = stringIDToTypeID( "maskIndicator" );
var idselectedAreas = stringIDToTypeID( "selectedAreas" );
desc368.putEnumerated( idcolorIndicates, idmaskIndicator, idselectedAreas );
var idchannel = stringIDToTypeID( "channel" );
desc367.putObject( idto, idchannel, desc368 );
executeAction( idset, desc367, DialogModes.NO );
Here it is in a function with a parameter/variable (scriptinglistener code passed through CleanSL + a manual variable and parameter added):
setQM("selectedAreas"); // or "maskedAreas"
function setQM(qmOption) {
var s2t = function (s) {
return app.stringIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var descriptor2 = new ActionDescriptor();
var reference = new ActionReference();
reference.putEnumerated( s2t( "channel" ), s2t( "ordinal" ), s2t( "targetEnum" ));
descriptor.putReference(s2t("null"), reference);
/* "selectedAreas" or "maskedAreas" */
descriptor2.putEnumerated( s2t( "colorIndicates" ), s2t( "maskIndicator" ), s2t( qmOption ));
descriptor.putObject( s2t( "to" ), s2t( "channel" ), descriptor2 );
executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}
Another option would be to simply select the Quick Mask channel and invert.
selectChannelByName("Quick Mask");
var idinvert = stringIDToTypeID( "invert" );
executeAction( idinvert, undefined, DialogModes.NO );
//app.activeDocument.activeChannels = app.activeDocument.componentChannels;
function selectChannelByName(channelName) {
var channelByName = new Array(app.activeDocument.channels[channelName]);
app.activeDocument.activeChannels = channelByName;
}