Store current selection as channel
function storeCurrentSelection(channelName,deselect){ // Input the name you want for your channel and if it should deselect or not
// Will delete any channel with the same name
try { activeDocument.channels.getByName(channelName).remove(); } catch(e) {}
var chanRef = app.activeDocument.channels.add();
chanRef.name = channelName;
chanRef.kind = ChannelType.SELECTEDAREA;
app.activeDocument.selection.store( app.activeDocument.channels.getByName(channelName), SelectionType.EXTEND );
// Deselect if the input of "deslect" is true
if (deselect) app.activeDocument.selection.deselect();
// Select the RGB channel instead of the mask channel
var id248 = charIDToTypeID( "slct" );
var desc48 = new ActionDescriptor();
var id249 = charIDToTypeID( "null" );
var ref36 = new ActionReference();
var id250 = charIDToTypeID( "Chnl" );
var id251 = charIDToTypeID( "Chnl" );
var id252 = charIDToTypeID( "RGB " );
ref36.putEnumerated( id250, id251, id252 );
desc48.putReference( id249, ref36 );
var id253 = charIDToTypeID( "MkVs" );
desc48.putBoolean( id253, false );
executeAction( id248, desc48, DialogModes.NO );
}