Skip to content

Instantly share code, notes, and snippets.

@silicontrip
Created January 18, 2021 22:45
Show Gist options
  • 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

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