try{
app.showColorPicker(true);

var myColor = app.foregroundColor;
var myL = myColor.lab.l;


var idClrR = charIDToTypeID( "ClrR" );
    var desc183 = new ActionDescriptor();
    var idFzns = charIDToTypeID( "Fzns" );
    desc183.putInteger( idFzns, 100 );
    var idMnm = charIDToTypeID( "Mnm " );
        var desc184 = new ActionDescriptor();
        var idLmnc = charIDToTypeID( "Lmnc" );
        desc184.putDouble( idLmnc, myL );
        var idA = charIDToTypeID( "A   " );
        desc184.putDouble( idA,-100 );
        var idB = charIDToTypeID( "B   " );
        desc184.putDouble( idB, -100);
    var idLbCl = charIDToTypeID( "LbCl" );
    desc183.putObject( idMnm, idLbCl, desc184 );
    var idMxm = charIDToTypeID( "Mxm " );
        var desc185 = new ActionDescriptor();
        var idLmnc = charIDToTypeID( "Lmnc" );
        desc185.putDouble( idLmnc, myL );
        var idA = charIDToTypeID( "A   " );
        desc185.putDouble( idA, 100 );
        var idB = charIDToTypeID( "B   " );
        desc185.putDouble( idB, 100 );
    var idLbCl = charIDToTypeID( "LbCl" );
    desc183.putObject( idMxm, idLbCl, desc185 );
    var idcolorModel = stringIDToTypeID( "colorModel" );
    desc183.putInteger( idcolorModel, 0 );
executeAction( idClrR, desc183, DialogModes.NO );

var idMk = charIDToTypeID( "Mk  " );
    var desc296 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref94 = new ActionReference();
        var idAdjL = charIDToTypeID( "AdjL" );
        ref94.putClass( idAdjL );
    desc296.putReference( idnull, ref94 );
    var idUsng = charIDToTypeID( "Usng" );
        var desc297 = new ActionDescriptor();
        var idType = charIDToTypeID( "Type" );
            var desc298 = new ActionDescriptor();
            var idpresetKind = stringIDToTypeID( "presetKind" );
            var idpresetKindType = stringIDToTypeID( "presetKindType" );
            var idpresetKindDefault = stringIDToTypeID( "presetKindDefault" );
            desc298.putEnumerated( idpresetKind, idpresetKindType, idpresetKindDefault );
        var idCrvs = charIDToTypeID( "Crvs" );
        desc297.putObject( idType, idCrvs, desc298 );
    var idAdjL = charIDToTypeID( "AdjL" );
    desc296.putObject( idUsng, idAdjL, desc297 );
executeAction( idMk, desc296, DialogModes.NO );


app.activeDocument.activeLayer.name = "Mask";
$.setenv("_rayapro_fuziness",100);

var idslct = charIDToTypeID( "slct" );
    var desc385 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref132 = new ActionReference();
        var idLyr = charIDToTypeID( "Lyr " );
        ref132.putName( idLyr, "Mask" );
    desc385.putReference( idnull, ref132 );
    var idMkVs = charIDToTypeID( "MkVs" );
    desc385.putBoolean( idMkVs, true );
executeAction( idslct, desc385, DialogModes.NO );
}catch(e){alert(e)}