4 Replies Latest reply on Sep 25, 2011 1:24 AM by c.pfaffenbichler

    changing crop tool settings with actiondescriptor code

    c.pfaffenbichler Level 9

      I would apppreciate some help – actually I’m looking for some code outright, because I haven’t been able to figure it out.

      And I have not been able to locate it in stdlib etc.

       

      Anyway, somebody asked about switching the Crop Tools horizontal and vertical settings via shortcut and as I could not find the button it in Keyboard Shortcuts I figured a Script might work.

      Using code from xbytor and Michael L Hale I could get the current settings (see below), but I have failed in feeding anything back in the proper form.

      I suppose the Actiondesciptor in the Actiondescriptor is too complicated for me.

       

      So could one of you please provide code that changes the Crop Tool settings?

       

      // based on xbytor code and additional code by michael l hale;
      // 2011, use it at your own risk;
      #target photoshop
      cTID = function(s) { return cTID[s] || cTID[s] = app.charIDToTypeID(s); };
      sTID = function(s) { return sTID[s] || sTID[s] = app.stringIDToTypeID(s); };
      ////// function to determine which tool is selected //////
      function getCurrentTool() {
      var ref = new ActionReference(); 
      ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
      return typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID("tool")));
      };
      ////// function to determine current tool options //////
      function getCurrentToolOptions () {
      var ref = new ActionReference();
      ref.putEnumerated(cTID("capp"), cTID("Ordn"), cTID("Trgt") );
      var desc = executeActionGet(ref);
      return desc.hasKey(cTID("CrnT")) ? desc.getObjectValue(cTID("CrnT")) : undefined;
      };
      ////////////////////////////////////
      // only if crop tool is selected;
      var curentTool = getCurrentTool();
      if (curentTool == "cropTool") {
      // get the crop tool options;
      var currentToolOpt = getCurrentToolOptions ();
      var cropOpt = currentToolOpt.getObjectValue(currentToolOpt.getKey(0));
      ////////////////////////////////////
      var width = cropOpt.getUnitDoubleValue(cropOpt.getKey(0));
      var unitWidth = cropOpt.getInteger(cropOpt.getKey(1));
      var height = cropOpt.getUnitDoubleValue(cropOpt.getKey(2));
      var unitHeight = cropOpt.getInteger(cropOpt.getKey(3));
      var the4 = cropOpt.getInteger(cropOpt.getKey(4));///65536
      var theResUnit = cropOpt.getInteger(cropOpt.getKey(5));
      var the6Type = cropOpt.getObjectType(cropOpt.getKey(6));
      var the6Value = cropOpt.getObjectValue(cropOpt.getKey(6));
      var the7 = cropOpt.getInteger(cropOpt.getKey(7));
      var the8 = cropOpt.getInteger(cropOpt.getKey(8));
      var the9 = cropOpt.getBoolean(cropOpt.getKey(9));
      var the10 = cropOpt.getBoolean(cropOpt.getKey(10));
      var the11 = cropOpt.getBoolean(cropOpt.getKey(11));
      //
      alert (width + "\n"+ unitWidth + "\n"+ height + "\n"
      + unitHeight + "\n"+ the4 + "\n"+ theResUnit + "\ntype "
      + the6Type + "\nvalue "+ the6Value + "\n"+ the7 + "\n"
      + the8 + "\n"+ the9 + "\n"+ the10 + "\n"+ the11);
      //
      };