Skip to content

Instantly share code, notes, and snippets.

@silicontrip
Created January 18, 2021 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silicontrip/069e7b4010fb816e4fbd58af5c1904f6 to your computer and use it in GitHub Desktop.
Save silicontrip/069e7b4010fb816e4fbd58af5c1904f6 to your computer and use it in GitHub Desktop.
rectangle selection photoshop
var idsetd = charIDToTypeID( "setd" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc12.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var desc13 = new ActionDescriptor();
var idTop = charIDToTypeID( "Top " );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idTop, idPxl, 3268.000000 );
var idLeft = charIDToTypeID( "Left" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idLeft, idPxl, 1328.000000 );
var idBtom = charIDToTypeID( "Btom" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idBtom, idPxl, 3716.000000 );
var idRght = charIDToTypeID( "Rght" );
var idPxl = charIDToTypeID( "#Pxl" );
desc13.putUnitDouble( idRght, idPxl, 5040.000000 );
var idRctn = charIDToTypeID( "Rctn" );
desc12.putObject( idT, idRctn, desc13 );
executeAction( idsetd, desc12, DialogModes.NO );
@silicontrip
Copy link
Author

working backwards, we see a single action being executed, "setd" the descriptor 12 contains the arguments to the setd action. In this example setd requires: An Object, with a key of T, a class of Rectangle, and the arguments from descriptor 13. Which holds the 4 keys: "Top ", "Left", "Btom" and "Rght" with the type of UnitDouble. UnitDouble is comprised of a unit type and value. Setd also requires a default reference, which is a Property type containing the Class and value.

@silicontrip
Copy link
Author

silicontrip commented Jan 18, 2021

Top = 3268 pixels
Btom = 3716 pixels
Left = 1328 pixels;
Rght = 5040 pixels;
T = Rctn(Rght, Btom, Left, Top)
_ = Property (Chnl, fsel)
setd ( Object T, Ref _ )

@silicontrip
Copy link
Author

Because many parameters are named, maybe I should use Objective-c style prototypes

  • (void)setd:(Ref)ref1 T:(Rctn)desc13;
  • (Rctn)initTop:(UnitDouble)top Left:(UnitDouble)left Bottom:(UnitDouble):btom Right:(UnitDouble)rght;
  • (UnitDouble)initWithType:(EnumType)idType value:(double)v;

@silicontrip
Copy link
Author

silicontrip commented Jan 21, 2021

This is the prototype syntax style I'm using for the documentation. It captures both the 4CC commands and the string counterpart, seperated by | 4cc|string. The named variable, is the key name, _ being used as the null key. The variables are broken out into their type and example value. Object types are broken out, using a similar parameter style to the function call. And individual object elements are indented and listed like function parameters. Types such as Object, Enumerated, Reference, List require additional parameters which are captured in <> like generics prototype. Other types may also require multiple parameters, are using colon separation on the variable line.

setd | set (Object<Rctn|rectangle>: T, Reference<Property>: _)
T: Rctn|rectangle(UnitDouble: Top|top, UnitDouble: Left|left, UnitDouble: Btom|bottom, UnitDouble: Rght|right)
	Top|top: #Pxl|pixelsUnit: 3268.000000
	Left|left: #Pxl|pixelsUnit: 1382.000000
	Btom|bottom: Pxl|pixelsUnit: 1382.000000
	Rght|right: Pxl|pixelsUnit: 1382.000000
_: Property: Chnl|channel: fsel|selection

@silicontrip
Copy link
Author

The above example, should capture enough detail to recreate the function in the obscure Action Manager call type. The function ID is 'setd' in charIDToTypeID or 'set' in stringIDToTypeID. This is the first argument to the executeAction() call. Parameters and Objects are made using ActionDescriptors. The parameter block, is the second argument and is type ActionDescriptor. Action Descriptors are Key value type triplets. The Key has been captured as the named variable, here we have T and _ (null) T is of type object, using the descriptor method putObject() which also requires another descriptor. The Type of the object is shown in <> details about the structure of the object are shown in a similar fashion as the function. (Type: name,...) these arguments are again broken out on the following lines. Working backwards, we need 4 UnitDouble types containing a unittype of pixelsUnit, and their required values. These are added to a descriptor with the the keys top,left,bottom and right, that descriptor is added as an object to the parameters descriptor, along with the null key of type Reference being made from an Action Reference containing a Property Type showing channel = selection.

@silicontrip
Copy link
Author

An xml object representing the ActionDescriptor used for selecting (setting) a rectangular marquee. Based on the Apple .plist structure. This format more accurately represents the ActionDescriptor than the previous description, in both the order of the keys isn't important and that a text values type can accurately specified also nested objects can be represented. This could be programmatically converted into a Descriptor object suitable for sending to the executeAction function. These XML files were generated programmatically, from an executeAction call.

<?xml version="1.0"?>
<Action>
  <Type>set</Type>
  <Descriptor>
    <Key>null</Key>
    <Reference>
      <Class>channel</Class>
      <Property>selection</Property>
    </Reference>
    <Key>to</Key>
    <Object>
      <Type>rectangle</Type>
      <Descriptor>
        <Key>top</Key>
        <UnitDouble>
          <Type>pixelsUnit</Type>
          <Value>3268</Value>
        </UnitDouble>
        <Key>left</Key>
        <UnitDouble>
          <Type>pixelsUnit</Type>
          <Value>1328</Value>
        </UnitDouble>
        <Key>bottom</Key>
        <UnitDouble>
          <Type>pixelsUnit</Type>
          <Value>3716</Value>
        </UnitDouble>
        <Key>right</Key>
        <UnitDouble>
          <Type>pixelsUnit</Type>
          <Value>5040</Value>
        </UnitDouble>
      </Descriptor>
    </Object>
  </Descriptor>
</Action>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment