Action to JavaScript conversion problem

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

yogiyang

Action to JavaScript conversion problem

Post by yogiyang »

I have got a small action which when I convert to JavaScripts and try to execute, it gives error, which I am not able to understand.

I am using XTools 1.5

The generated JavaScript
Code: Select all//
// Generated Tue Oct 23 2007 07:32:57 GMT+0530
//

//
//==================== Correct Underexpose ==============
//

//I thought there was error on these lines so I moved them to the top
//But yet could not make head or tail of the error message shown by PS
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

  // Flatten Image
function CorrectUnderexpose() {
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('flattenImage'), undefined, dialogMode);
  };

  // Layer Via Copy
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('copyToLayer'), undefined, dialogMode);
  };

  // Layer Via Copy
  function step3(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('copyToLayer'), undefined, dialogMode);
  };

  // Levels
  function step4(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var list1 = new ActionList();
    var desc2 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(PSClass.Channel, PSClass.Channel, PSEnum.Composite);
    desc2.putReference(PSClass.Channel, ref1);
    var list2 = new ActionList();
    list2.putInteger(0);
    list2.putInteger(0);
    desc2.putList(PSKey.Input, list2);
    desc2.putDouble(PSKey.Gamma, 1.19);
    desc1.putList(PSKey.Adjustment, list1);
    executeAction(PSEvent.Levels, desc1, dialogMode);
  };

  // Set
  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.Layer, PSType.Ordinal, PSEnum.Target);
    desc1.putReference(PSString.Null, ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(PSKey.Mode, PSType.BlendMode, PSEnum.Screen);
    desc1.putObject(PSKey.To, PSClass.Layer, desc2);
    executeAction(PSEvent.Set, desc1, dialogMode);
  };

  // Shadow/Highlight
  function step6(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(PSKey.Amount, PSUnit.Percent, 50);
    desc2.putUnitDouble(PSKey.Width, PSUnit.Percent, 50);
    desc2.putInteger(PSKey.Radius, 30);
    desc1.putObject(PSKey.ShadowMode, cTID('288'), desc2);
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble(PSKey.Amount, PSUnit.Percent, 0);
    desc3.putUnitDouble(PSKey.Width, PSUnit.Percent, 50);
    desc3.putInteger(PSKey.Radius, 30);
    desc1.putObject(PSKey.HighlightMode, cTID('288'), desc3);
    desc1.putDouble(PSKey.BlackClip, 0.01);
    desc1.putDouble(PSKey.WhiteClip, 0.01);
    desc1.putInteger(PSKey.Contrast, 0);
    desc1.putInteger(PSKey.ColorCorrection, 20);
    executeAction(sTID('adaptCorrect'), desc1, dialogMode);
  };

  // Merge Layers
  function step7(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    executeAction(sTID('mergeLayersNew'), desc1, dialogMode);
  };

  // Stop
  function step8(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putString(PSKey.Message, "Pl. set opacity");
    executeAction(PSEvent.Stop, desc1, dialogMode);
  };

  // Flatten Image
  function step9(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('flattenImage'), undefined, dialogMode);
  };

  step1();      // Flatten Image
  step2();      // Layer Via Copy
  step3();      // Layer Via Copy
  step4();      // Levels
  step5();      // Set
  step6();      // Shadow/Highlight
  step7();      // Merge Layers
  step8(true, true);      // Stop
  step9();      // Flatten Image
};





//
// CorrectUnderexpose.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.
//
CorrectUnderexpose.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.Channel = cTID('Chnl');
  PSClass.Layer = cTID('Lyr ');
  PSEnum.Composite = cTID('Cmps');
  PSEnum.Screen = cTID('Scrn');
  PSEnum.Target = cTID('Trgt');
  PSEvent.Levels = cTID('Lvls');
  PSEvent.Set = cTID('setd');
  PSEvent.Stop = cTID('Stop');
  PSKey.Adjustment = cTID('Adjs');
  PSKey.Amount = cTID('Amnt');
  PSKey.BlackClip = cTID('BlcC');
  PSKey.ColorCorrection = cTID('ClrC');
  PSKey.Contrast = cTID('Cntr');
  PSKey.Gamma = cTID('Gmm ');
  PSKey.HighlightMode = cTID('hglM');
  PSKey.Input = cTID('Inpt');
  PSKey.Message = cTID('Msge');
  PSKey.Mode = cTID('Md  ');
  PSKey.Radius = cTID('Rds ');
  PSKey.ShadowMode = cTID('sdwM');
  PSKey.To = cTID('T   ');
  PSKey.WhiteClip = cTID('WhtC');
  PSKey.Width = cTID('Wdth');
  PSString.Null = sTID('null');
  PSType.BlendMode = cTID('BlnM');
  PSType.Ordinal = cTID('Ordn');
  PSUnit.Percent = cTID('#Prc');
};

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



//=========================================
//                    CorrectUnderexpose.main
//=========================================
//

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

CorrectUnderexpose.main();

// EOF

xbytor

Action to JavaScript conversion problem

Post by xbytor »

The problem is with the lines that look like this:
Code: Select all   desc1.putObject(PSKey.HighlightMode, cTID('288'), desc3);

The cTID('288') is wrong. I'll see what I can do with it.

-X
xbytor

Action to JavaScript conversion problem

Post by xbytor »

I posted an update that addresses this problem in a new thread.

-X
yogiyang

Action to JavaScript conversion problem

Post by yogiyang »

Thank you -X