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

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