//
// Generated Thu Apr 30 2015 23:13:25 GMT+0600
//

//
//==================== Black & White ==============
//
function Black_White() {
  // Make
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(PSString.contentLayer);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    var desc3 = new ActionDescriptor();
    var desc4 = new ActionDescriptor();
    desc4.putDouble(PSEnum.Red, 127.998046875);
    desc4.putDouble(PSEnum.Green, 127.998046875);
    desc4.putDouble(PSEnum.Blue, 127.998046875);
    desc3.putObject(PSKey.Color, PSClass.RGBColor, desc4);
    desc2.putObject(PSKey.Type, PSString.solidColorLayer, desc3);
    desc1.putObject(PSKey.Using, PSString.contentLayer, desc2);
    executeAction(PSEvent.Make, desc1, dialogMode);
  };

  // Set
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(PSKey.Color, PSKey.Color, PSEnum.Blue);
    desc1.putObject(PSKey.To, PSClass.Layer, desc2);
    executeAction(PSEvent.Set, desc1, dialogMode);
  };

  // Set
  function step3(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(PSKey.Name, "Black & White");
    desc1.putObject(PSKey.To, PSClass.Layer, desc2);
    executeAction(PSEvent.Set, desc1, dialogMode);
  };

  // Set
  function step4(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Layer, PSType.Ordinal, PSEnum.Target);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(PSKey.Mode, PSType.BlendMode, PSKey.Color);
    desc1.putObject(PSKey.To, PSClass.Layer, desc2);
    executeAction(PSEvent.Set, desc1, dialogMode);
  };

  // Select
  function step5(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSClass.Mask);
    desc1.putReference(PSString.Null, ref1);
    desc1.putBoolean(PSKey.MakeVisible, false);
    executeAction(PSEvent.Select, desc1, dialogMode);
  };

  // Delete
  function step6(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Channel, PSType.Ordinal, PSEnum.Target);
    desc1.putReference(PSString.Null, ref1);
    executeAction(PSEvent.Delete, desc1, dialogMode);
  };

  step1();      // Make
  step2();      // Set
  step3();      // Set
  step4();      // Set
  step5();      // Select
  step6();      // Delete
};



cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
// Black_White.loadSymbols
//   Loading up the symbol definitions like this makes it possible
//   to include several of these generated files in one master file
//   provided a prefix is specified other than the default. It also
//   skips the definitions if PSConstants has already been loaded.
//
Black_White.loadSymbols = function() {
  var dbgLevel = $.level;
  $.level = 0;
  try {
    PSConstants;
    return; // only if PSConstants is defined
  } catch (e) {
  } finally {
    $.level = dbgLevel;
  }
  var needDefs = true;
  $.level = 0;
  try {
    PSClass;
    needDefs = false;
  } catch (e) {
  } finally {
    $.level = dbgLevel;
  }
  if (needDefs) {
    PSClass = function() {};
    PSEnum = function() {};
    PSEvent = function() {};
    PSForm = function() {};
    PSKey = function() {};
    PSType = function() {};
    PSUnit = function() {};
    PSString = function() {};
  }

  // We may still end up duplicating some of the following definitions
  // but at least we don't redefine PSClass, etc... and wipe out others
  PSClass.AdjustmentLayer = cTID('AdjL');
  PSClass.Calculation = cTID('Clcl');
  PSClass.Channel = cTID('Chnl');
  PSClass.Curves = cTID('Crvs');
  PSClass.CurvesAdjustment = cTID('CrvA');
  PSClass.Layer = cTID('Lyr ');
  PSClass.Mask = cTID('Msk ');
  PSClass.Point = cTID('Pnt ');
  PSClass.RGBColor = cTID('RGBC');
  PSEnum.Blue = cTID('Bl  ');
  PSEnum.Composite = cTID('Cmps');
  PSEnum.Green = cTID('Grn ');
  PSEnum.HideAll = cTID('HdAl');
  PSEnum.Luminosity = cTID('Lmns');
  PSEnum.Merged = cTID('Mrgd');
  PSEnum.Overlay = cTID('Ovrl');
  PSEnum.RGB = cTID('RGB ');
  PSEnum.Red = cTID('Rd  ');
  PSEnum.Target = cTID('Trgt');
  PSEvent.Delete = cTID('Dlt ');
  PSEvent.Desaturate = cTID('Dstt');
  PSEvent.Make = cTID('Mk  ');
  PSEvent.Select = cTID('slct');
  PSEvent.Set = cTID('setd');
  PSKey.Adjustment = cTID('Adjs');
  PSKey.At = cTID('At  ');
  PSKey.Color = cTID('Clr ');
  PSKey.Curve = cTID('Crv ');
  PSKey.Exposure = cTID('Exps');
  PSKey.From = cTID('From');
  PSKey.Horizontal = cTID('Hrzn');
  PSKey.MakeVisible = cTID('MkVs');
  PSKey.Mapping = cTID('Mpng');
  PSKey.Mode = cTID('Md  ');
  PSKey.Name = cTID('Nm  ');
  PSKey.New = cTID('Nw  ');
  PSKey.Offset = cTID('Ofst');
  PSKey.Opacity = cTID('Opct');
  PSKey.Radius = cTID('Rds ');
  PSKey.To = cTID('T   ');
  PSKey.Type = cTID('Type');
  PSKey.Using = cTID('Usng');
  PSKey.Vertical = cTID('Vrtc');
  PSKey.With = cTID('With');
  PSString.EXIF = sTID('EXIF');
  PSString.Null = sTID('null');
  PSString.OpenGLEnabled = sTID('openglEnabled');
  PSString.PromptedForColorSetup = sTID('promptedForColorSetup');
  PSString.RGBFloatColor = sTID('RGBFloatColor');
  PSString.addKnotTool = sTID('addKnotTool');
  PSString.addToSelectionContinuous = sTID('addToSelectionContinuous');
  PSString.animationKey = sTID('animationKey');
  PSString.askLayeredTIFF = sTID('askLayeredTIFF');
  PSString.assetManagementEnabled = sTID('assetManagementEnabled');
  PSString.autoCollapseDrawers = sTID('autoCollapseDrawers');
  PSString.average = sTID('average');
  PSString.blueFloat = sTID('blueFloat');
  PSString.bucketTool = sTID('bucketTool');
  PSString.cameraRaw = sTID('cameraRaw');
  PSString.canvasBackgroundColors = sTID('canvasBackgroundColors');
  PSString.canvasColorMode = sTID('canvasColorMode');
  PSString.colorReplacementBrushTool = sTID('colorReplacementBrushTool');
  PSString.colorSamplerTool = sTID('colorSamplerTool');
  PSString.contentLayer = sTID('contentLayer');
  PSString.convertKnotTool = sTID('convertKnotTool');
  PSString.countTool = sTID('countTool');
  PSString.cropTool = sTID('cropTool');
  PSString.cursorCrosshair = sTID('cursorCrosshair');
  PSString.cursorShape = sTID('cursorShape');
  PSString.customShape = sTID('customShape');
  PSString.customShapeTool = sTID('customShapeTool');
  PSString.deleteKnotTool = sTID('deleteKnotTool');
  PSString.directSelectTool = sTID('directSelectTool');
  PSString.editLogItems = sTID('editLogItems');
  PSString.ellipseTool = sTID('ellipseTool');
  PSString.enableFontFallback = sTID('enableFontFallback');
  PSString.excludeIntersection = sTID('excludeIntersection');
  PSString.eyedropperTool = sTID('eyedropperTool');
  PSString.flow = sTID('flow');
  PSString.fontPreviewsSize = sTID('fontPreviewsSize');
  PSString.freeformPenTool = sTID('freeformPenTool');
  PSString.gammaCorrection = sTID('gammaCorrection');
  PSString.gradientLayer = sTID('gradientLayer');
  PSString.grayscaleFloat = sTID('grayscaleFloat');
  PSString.greenFloat = sTID('greenFloat');
  PSString.handTool = sTID('handTool');
  PSString.historyLog = sTID('historyLog');
  PSString.lassoTool = sTID('lassoTool');
  PSString.layerGroup = sTID('layerSection');
  PSString.lineTool = sTID('lineTool');
  PSString.magicStampTool = sTID('magicStampTool');
  PSString.magicWandTool = sTID('magicWandTool');
  PSString.magneticLassoTool = sTID('magneticLassoTool');
  PSString.marqueeEllipTool = sTID('marqueeEllipTool');
  PSString.marqueeRectTool = sTID('marqueeRectTool');
  PSString.marqueeSingleColumnTool = sTID('marqueeSingleColumnTool');
  PSString.marqueeSingleRowTool = sTID('marqueeSingleRowTool');
  PSString.maximizeCompatibility = sTID('maximizeCompatibility');
  PSString.moveTool = sTID('moveTool');
  PSString.newDocPresetPrintResolution = sTID('newDocPresetPrintResolution');
  PSString.newDocPresetPrintScale = sTID('newDocPresetPrintScale');
  PSString.newDocPresetScreenResolution = sTID('newDocPresetScreenResolution');
  PSString.newDocPresetScreenScale = sTID('newDocPresetScreenScale');
  PSString.opacityFloat = sTID('opacityFloat');
  PSString.patchSelection = sTID('patchSelection');
  PSString.pathComponentSelectTool = sTID('pathComponentSelectTool');
  PSString.patternLayer = sTID('patternLayer');
  PSString.pdf13 = sTID('pdf13');
  PSString.pdf14 = sTID('pdf14');
  PSString.pdf15 = sTID('pdf15');
  PSString.pdf16 = sTID('pdf16');
  PSString.pdf17 = sTID('pdf17');
  PSString.pdfx1a2001 = sTID('pdfx1a2001');
  PSString.pdfx1a2003 = sTID('pdfx1a2003');
  PSString.pdfx32001 = sTID('pdfx32001');
  PSString.pdfx32003 = sTID('pdfx32003');
  PSString.penTool = sTID('penTool');
  PSString.performance = sTID('performance');
  PSString.photoFilter = sTID('photoFilter');
  PSString.polySelTool = sTID('polySelTool');
  PSString.polygonTool = sTID('polygonTool');
  PSString.presetKind = sTID('presetKind');
  PSString.presetKindCustom = sTID('presetKindCustom');
  PSString.presetKindDefault = sTID('presetKindDefault');
  PSString.presetKindType = sTID('presetKindType');
  PSString.quickSelectTool = sTID('quickSelectTool');
  PSString.rectangleTool = sTID('rectangleTool');
  PSString.redEyeTool = sTID('redEyeTool');
  PSString.redFloat = sTID('redFloat');
  PSString.replace = sTID('replace');
  PSString.resizePastePlace = sTID('resizePastePlace');
  PSString.rotateTool = sTID('rotateTool');
  PSString.roundedRectangleTool = sTID('roundedRectangleTool');
  PSString.rulerTool = sTID('rulerTool');
  PSString.saveHistoryTo = sTID('saveHistoryTo');
  PSString.screenMode = sTID('screenMode');
  PSString.screenModeFullScreen = sTID('screenModeFullScreen');
  PSString.screenModeFullScreenWithMenubar = sTID('screenModeFullScreenWithMenubar');
  PSString.screenModeStandard = sTID('screenModeStandard');
  PSString.selectedItems = sTID('selectedItems');
  PSString.selectionModifier = sTID('selectionModifier');
  PSString.selectionModifierType = sTID('selectionModifierType');
  PSString.shapeClass = sTID('shapeClass');
  PSString.shapeburst = sTID('shapeburst');
  PSString.showCJKFeatures = sTID('showCJKFeatures');
  PSString.showFontPreviews = sTID('showFontPreviews');
  PSString.showMenuColors = sTID('showMenuColors');
  PSString.sliceSelectTool = sTID('sliceSelectTool');
  PSString.sliceTool = sTID('sliceTool');
  PSString.smartQuotes = sTID('smartQuotes');
  PSString.solidColorLayer = sTID('solidColorLayer');
  PSString.spotHealingBrushTool = sTID('spotHealingBrushTool');
  PSString.subsample = sTID('subsample');
  PSString.textAnnotTool = sTID('textAnnotTool');
  PSString.toolPreset = sTID('toolPreset');
  PSString.typeCreateMaskTool = sTID('typeCreateMaskTool');
  PSString.typeCreateOrEditTool = sTID('typeCreateOrEditTool');
  PSString.typeUnits = sTID('typeUnits');
  PSString.typeVerticalCreateMaskTool = sTID('typeVerticalCreateMaskTool');
  PSString.typeVerticalCreateOrEditTool = sTID('typeVerticalCreateOrEditTool');
  PSString.workingCMYK = sTID('workingCMYK');
  PSString.workingRGB = sTID('workingRGB');
  PSString.zoomTool = sTID('zoomTool');
  PSString.zoomWithScrollWheel = sTID('zoomWithScrollWheel');
  PSType.BlendMode = cTID('BlnM');
  PSType.Ordinal = cTID('Ordn');
  PSType.UserMaskOptions = cTID('UsrM');
  PSUnit.Percent = cTID('#Prc');
  PSUnit.Pixels = cTID('#Pxl');
};

Black_White.loadSymbols(); // load up our symbols



//=========================================
//                    Black_White.main
//=========================================
//

Black_White.main = function () {
  Black_White();
};

Black_White.main();

// EOF
