win = new Window("dialog", "胶片颗粒");
win.orientation = "column";
leftGr = win.add("group");
leftGr.orientation = "column";
sliderGroup46 = leftGr.add("group");
slTxt3 = sliderGroup46.add("staticText", undefined, " 增加噪点");
sliderGroup = leftGr.add("group");
sliderGroup.orientation = "row";
sliderGroup.alignChildren = ["fill", "fill"];
slTxt = sliderGroup.add("staticText", undefined, "0");
sliderA = sliderGroup.add("slider", undefined, 0, 0, 100);
sliderA.preferredSize.width = 275;
sliderValueA = sliderGroup.add("statictext", undefined, " 100 ");
sliderA.onChanging = function() {
    sliderValueA.text = Math.round(this.value);
};
sliderA.onChange = function() {
    foo = Math.round(this.value);
    foo2 = foo / 2;
    var idslct = charIDToTypeID("slct");
    var desc195 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref126 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    ref126.putName(idLyr, "Film Grain");
    desc195.putReference(idnull, ref126);
    var idMkVs = charIDToTypeID("MkVs");
    desc195.putBoolean(idMkVs, false);
    var idLyrI = charIDToTypeID("LyrI");
    var list9 = new ActionList();
    list9.putInteger(34);
    desc195.putList(idLyrI, list9);
    executeAction(idslct, desc195, DialogModes.NO);
    var idsetd = charIDToTypeID("setd");
    var desc191 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref124 = new ActionReference();
    var idfilterFX = stringIDToTypeID("filterFX");
    ref124.putIndex(idfilterFX, 1);
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref124.putEnumerated(idLyr, idOrdn, idTrgt);
    desc191.putReference(idnull, ref124);
    var idfilterFX = stringIDToTypeID("filterFX");
    var desc192 = new ActionDescriptor();
    var idFltr = charIDToTypeID("Fltr");
    var desc193 = new ActionDescriptor();
    var idDstr = charIDToTypeID("Dstr");
    var idDstr = charIDToTypeID("Dstr");
    var idGsn = charIDToTypeID("Gsn ");
    desc193.putEnumerated(idDstr, idDstr, idGsn);
    var idNose = charIDToTypeID("Nose");
    var idPrc = charIDToTypeID("#Prc");
    desc193.putUnitDouble(idNose, idPrc, foo2);
    var idMnch = charIDToTypeID("Mnch");
    desc193.putBoolean(idMnch, true);
    var idFlRs = charIDToTypeID("FlRs");
    desc193.putInteger(idFlRs, 2226658);
    var idAdNs = charIDToTypeID("AdNs");
    desc192.putObject(idFltr, idAdNs, desc193);
    var idfilterFX = stringIDToTypeID("filterFX");
    desc191.putObject(idfilterFX, idfilterFX, desc192);
    executeAction(idsetd, desc191, DialogModes.NO);
    app.refresh();
};
sliderGroup45 = leftGr.add("group");
slTxt3 = sliderGroup45.add("staticText", undefined, "  高斯模糊");
sliderGroup = leftGr.add("group");
sliderGroup.orientation = "row";
sliderGroup.alignChildren = ["fill", "fill"];
slTxt = sliderGroup.add("staticText", undefined, "0");
sliderB = sliderGroup.add("slider", undefined, 0, 0, 100);
sliderB.preferredSize.width = 275;
sliderValueB = sliderGroup.add("statictext", undefined, " 100 ");
sliderB.onChanging = function() {
    sliderValueB.text = Math.round(this.value);
};
sliderB.onChange = function() {
    foo = Math.round(this.value);
    foo2 = foo / 10;
    var idslct = charIDToTypeID("slct");
    var desc197 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref128 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    ref128.putName(idLyr, "Film Grain");
    desc197.putReference(idnull, ref128);
    var idMkVs = charIDToTypeID("MkVs");
    desc197.putBoolean(idMkVs, false);
    var idLyrI = charIDToTypeID("LyrI");
    var list11 = new ActionList();
    list11.putInteger(34);
    desc197.putList(idLyrI, list11);
    executeAction(idslct, desc197, DialogModes.NO);
    var idsetd = charIDToTypeID("setd");
    var desc198 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref129 = new ActionReference();
    var idfilterFX = stringIDToTypeID("filterFX");
    ref129.putIndex(idfilterFX, 2);
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref129.putEnumerated(idLyr, idOrdn, idTrgt);
    desc198.putReference(idnull, ref129);
    var idfilterFX = stringIDToTypeID("filterFX");
    var desc199 = new ActionDescriptor();
    var idFltr = charIDToTypeID("Fltr");
    var desc200 = new ActionDescriptor();
    var idRds = charIDToTypeID("Rds ");
    var idPxl = charIDToTypeID("#Pxl");
    desc200.putUnitDouble(idRds, idPxl, foo2);
    var idGsnB = charIDToTypeID("GsnB");
    desc199.putObject(idFltr, idGsnB, desc200);
    var idfilterFX = stringIDToTypeID("filterFX");
    desc198.putObject(idfilterFX, idfilterFX, desc199);
    executeAction(idsetd, desc198, DialogModes.NO);
    app.refresh();
};
sliderGroup47 = leftGr.add("group");
slTxt3 = sliderGroup47.add("staticText", undefined, "  锐化");
sliderGroup = leftGr.add("group");
sliderGroup.orientation = "row";
sliderGroup.alignChildren = ["fill", "fill"];
slTxt = sliderGroup.add("staticText", undefined, "0");
sliderC = sliderGroup.add("slider", undefined, 5, 0, 100);
sliderC.preferredSize.width = 275;
sliderValueC = sliderGroup.add("statictext", undefined, " 100 ");
sliderC.onChanging = function() {
    sliderValueC.text = Math.round(this.value);
};
sliderC.onChange = function() {
    foo = Math.round(this.value);
    foo2 = foo * 5;
    foo3 = foo / 15;
    var idslct = charIDToTypeID("slct");
    var desc197 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref128 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    ref128.putName(idLyr, "Film Grain");
    desc197.putReference(idnull, ref128);
    var idMkVs = charIDToTypeID("MkVs");
    desc197.putBoolean(idMkVs, false);
    var idLyrI = charIDToTypeID("LyrI");
    var list11 = new ActionList();
    list11.putInteger(34);
    desc197.putList(idLyrI, list11);
    executeAction(idslct, desc197, DialogModes.NO);
    var idsetd = charIDToTypeID("setd");
    var desc201 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref130 = new ActionReference();
    var idfilterFX = stringIDToTypeID("filterFX");
    ref130.putIndex(idfilterFX, 3);
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref130.putEnumerated(idLyr, idOrdn, idTrgt);
    desc201.putReference(idnull, ref130);
    var idfilterFX = stringIDToTypeID("filterFX");
    var desc202 = new ActionDescriptor();
    var idFltr = charIDToTypeID("Fltr");
    var desc203 = new ActionDescriptor();
    var idAmnt = charIDToTypeID("Amnt");
    var idPrc = charIDToTypeID("#Prc");
    desc203.putUnitDouble(idAmnt, idPrc, foo2);
    var idRds = charIDToTypeID("Rds ");
    var idPxl = charIDToTypeID("#Pxl");
    desc203.putUnitDouble(idRds, idPxl, foo3);
    var idThsh = charIDToTypeID("Thsh");
    desc203.putInteger(idThsh, 0);
    var idUnsM = charIDToTypeID("UnsM");
    desc202.putObject(idFltr, idUnsM, desc203);
    var idfilterFX = stringIDToTypeID("filterFX");
    desc201.putObject(idfilterFX, idfilterFX, desc202);
    executeAction(idsetd, desc201, DialogModes.NO);
    app.refresh();
};
sliderGroup48 = leftGr.add("group");
slTxt3 = sliderGroup48.add("staticText", undefined, "  不透明度");
sliderGroup = leftGr.add("group");
sliderGroup.orientation = "row";
sliderGroup.alignChildren = ["fill", "fill"];
slTxt = sliderGroup.add("staticText", undefined, "0");
sliderD = sliderGroup.add("slider", undefined, 100, 0, 100);
sliderD.preferredSize.width = 275;
sliderValueD = sliderGroup.add("statictext", undefined, " 100 ");
sliderD.onChanging = function() {
    sliderValueD.text = Math.round(this.value);
};
sliderD.onChange = function() {
    foo = Math.round(this.value);
    var idslct = charIDToTypeID("slct");
    var desc195 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref126 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    ref126.putName(idLyr, "Film Grain");
    desc195.putReference(idnull, ref126);
    var idMkVs = charIDToTypeID("MkVs");
    desc195.putBoolean(idMkVs, false);
    var idLyrI = charIDToTypeID("LyrI");
    var list9 = new ActionList();
    list9.putInteger(34);
    desc195.putList(idLyrI, list9);
    executeAction(idslct, desc195, DialogModes.NO);
    var idsetd = charIDToTypeID("setd");
    var desc228 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref144 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref144.putEnumerated(idLyr, idOrdn, idTrgt);
    desc228.putReference(idnull, ref144);
    var idT = charIDToTypeID("T   ");
    var desc229 = new ActionDescriptor();
    var idOpct = charIDToTypeID("Opct");
    var idPrc = charIDToTypeID("#Prc");
    desc229.putUnitDouble(idOpct, idPrc, foo);
    var idLyr = charIDToTypeID("Lyr ");
    desc228.putObject(idT, idLyr, desc229);
    executeAction(idsetd, desc228, DialogModes.NO);
    app.refresh();
};
leftGr = win.add("group");
flip1 = leftGr.add("button", undefined, "开始胶片颗粒风格处理");
flip1.preferredSize.width = 150;
closeBtn = leftGr.add("button", undefined, "关闭");
closeBtn.preferredSize.width = 150;
flip1.onClick = function() {
    if (app) {
        try {
            MainCatch3();
        } catch (e) {

        }
    }

    function MainCatch3() {
        var getName = app.activeDocument.activeLayer.name;
        var idslct = charIDToTypeID("slct");
        var desc410 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref300 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        ref300.putName(idLyr, "Film Grain");
        desc410.putReference(idnull, ref300);
        var idMkVs = charIDToTypeID("MkVs");
        desc410.putBoolean(idMkVs, false);
        var idLyrI = charIDToTypeID("LyrI");
        var list239 = new ActionList();
        list239.putInteger(94);
        desc410.putList(idLyrI, list239);
        executeAction(idslct, desc410, DialogModes.NO);
        var idsetd = charIDToTypeID("setd");
        var desc422 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref309 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        var idOrdn = charIDToTypeID("Ordn");
        var idTrgt = charIDToTypeID("Trgt");
        ref309.putEnumerated(idLyr, idOrdn, idTrgt);
        desc422.putReference(idnull, ref309);
        var idT = charIDToTypeID("T   ");
        var desc423 = new ActionDescriptor();
        var idNm = charIDToTypeID("Nm  ");
        desc423.putString(idNm, "Fillm Grain - old");
        var idLyr = charIDToTypeID("Lyr ");
        desc422.putObject(idT, idLyr, desc423);
        executeAction(idsetd, desc422, DialogModes.NO);
        var idsetd = charIDToTypeID("setd");
        var desc86 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref54 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        var idOrdn = charIDToTypeID("Ordn");
        var idTrgt = charIDToTypeID("Trgt");
        ref54.putEnumerated(idLyr, idOrdn, idTrgt);
        desc86.putReference(idnull, ref54);
        var idT = charIDToTypeID("T   ");
        var desc87 = new ActionDescriptor();
        var idClr = charIDToTypeID("Clr ");
        var idClr = charIDToTypeID("Clr ");
        var idNone = charIDToTypeID("None");
        desc87.putEnumerated(idClr, idClr, idNone);
        var idLyr = charIDToTypeID("Lyr ");
        desc86.putObject(idT, idLyr, desc87);
        executeAction(idsetd, desc86, DialogModes.NO);
        var idslct = charIDToTypeID("slct");
        var desc410 = new ActionDescriptor();
        var idnull = charIDToTypeID("null");
        var ref300 = new ActionReference();
        var idLyr = charIDToTypeID("Lyr ");
        ref300.putName(idLyr, getName);
        desc410.putReference(idnull, ref300);
        var idMkVs = charIDToTypeID("MkVs");
        desc410.putBoolean(idMkVs, false);
        var idLyrI = charIDToTypeID("LyrI");
        var list239 = new ActionList();
        list239.putInteger(94);
        desc410.putList(idLyrI, list239);
        executeAction(idslct, desc410, DialogModes.NO);
    }
    var idMk = charIDToTypeID("Mk  ");
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref1 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    ref1.putClass(idLyr);
    desc2.putReference(idnull, ref1);
    var idUsng = charIDToTypeID("Usng");
    var desc3 = new ActionDescriptor();
    var idNm = charIDToTypeID("Nm  ");
    desc3.putString(idNm, "Film Grain");
    var idMd = charIDToTypeID("Md  ");
    var idBlnM = charIDToTypeID("BlnM");
    var idSftL = charIDToTypeID("SftL");
    desc3.putEnumerated(idMd, idBlnM, idSftL);
    var idFlNt = charIDToTypeID("FlNt");
    desc3.putBoolean(idFlNt, true);
    var idLyr = charIDToTypeID("Lyr ");
    desc2.putObject(idUsng, idLyr, desc3);
    executeAction(idMk, desc2, DialogModes.NO);
    var idnewPlacedLayer = stringIDToTypeID("newPlacedLayer");
    executeAction(idnewPlacedLayer, undefined, DialogModes.NO);
    var idAdNs = charIDToTypeID("AdNs");
    var desc4 = new ActionDescriptor();
    var idDstr = charIDToTypeID("Dstr");
    var idDstr = charIDToTypeID("Dstr");
    var idGsn = charIDToTypeID("Gsn ");
    desc4.putEnumerated(idDstr, idDstr, idGsn);
    var idNose = charIDToTypeID("Nose");
    var idPrc = charIDToTypeID("#Prc");
    desc4.putUnitDouble(idNose, idPrc, 0);
    var idMnch = charIDToTypeID("Mnch");
    desc4.putBoolean(idMnch, true);
    var idFlRs = charIDToTypeID("FlRs");
    desc4.putInteger(idFlRs, 2226658);
    executeAction(idAdNs, desc4, DialogModes.NO);
    var idGsnB = charIDToTypeID("GsnB");
    var desc5 = new ActionDescriptor();
    var idRds = charIDToTypeID("Rds ");
    var idPxl = charIDToTypeID("#Pxl");
    desc5.putUnitDouble(idRds, idPxl, 0);
    executeAction(idGsnB, desc5, DialogModes.NO);
    var idUnsM = charIDToTypeID("UnsM");
    var desc6 = new ActionDescriptor();
    var idAmnt = charIDToTypeID("Amnt");
    var idPrc = charIDToTypeID("#Prc");
    desc6.putUnitDouble(idAmnt, idPrc, 20);
    var idRds = charIDToTypeID("Rds ");
    var idPxl = charIDToTypeID("#Pxl");
    desc6.putUnitDouble(idRds, idPxl, 2);
    var idThsh = charIDToTypeID("Thsh");
    desc6.putInteger(idThsh, 0);
    executeAction(idUnsM, desc6, DialogModes.NO);
    var idsetd = charIDToTypeID("setd");
    var desc23 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref15 = new ActionReference();
    var idLyr = charIDToTypeID("Lyr ");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref15.putEnumerated(idLyr, idOrdn, idTrgt);
    desc23.putReference(idnull, ref15);
    var idT = charIDToTypeID("T   ");
    var desc24 = new ActionDescriptor();
    var idClr = charIDToTypeID("Clr ");
    var idClr = charIDToTypeID("Clr ");
    var idYlw = charIDToTypeID("Ylw ");
    desc24.putEnumerated(idClr, idClr, idYlw);
    var idLyr = charIDToTypeID("Lyr ");
    desc23.putObject(idT, idLyr, desc24);
    executeAction(idsetd, desc23, DialogModes.NO);
    var idslct = charIDToTypeID("slct");
    var desc72 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref27 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idChnl = charIDToTypeID("Chnl");
    var idfilterMask = stringIDToTypeID("filterMask");
    ref27.putEnumerated(idChnl, idChnl, idfilterMask);
    desc72.putReference(idnull, ref27);
    var idMkVs = charIDToTypeID("MkVs");
    desc72.putBoolean(idMkVs, false);
    executeAction(idslct, desc72, DialogModes.NO);
    var idDlt = charIDToTypeID("Dlt ");
    var desc73 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    var ref28 = new ActionReference();
    var idChnl = charIDToTypeID("Chnl");
    var idOrdn = charIDToTypeID("Ordn");
    var idTrgt = charIDToTypeID("Trgt");
    ref28.putEnumerated(idChnl, idOrdn, idTrgt);
    desc73.putReference(idnull, ref28);
    executeAction(idDlt, desc73, DialogModes.NO);
    app.refresh();
};
close = false;
closeBtn.onClick = function() {
    close = true;
    win.close();
};
win.onClose = function() {
    close = true;
};
win.show();
while (close === false) {
    app.refresh();
}