Photoshop: Action Question (if path exists do) (if not do)

  • 1
  • Idea
  • Updated 4 years ago
  • (Edited)
I see all the nice new conditionals allowed in actions now, but I don't see one for paths. I see alpha channels and lots of other things, but nothing for paths. I get a variety of files that sometimes have a clipping path and sometimes do not. To trim down file size I like to make selections based on the path, expand it 12 pixels and crop the file. On files that don't have paths, id like it to do the rest of the action. Id like some form of option for conditionals for paths. Is this possible?
Photo of Tiemmothi

Tiemmothi

  • 12 Posts
  • 0 Reply Likes

Posted 4 years ago

  • 1
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1199 Posts
  • 159 Reply Likes
You could include a Script in the Action.

Edit: A Script like this might suffice:

// if clipping path exists expand selection from that by 12px and crop;
// 2013, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
var clippingPath = docDesc.getObjectValue (stringIDToTypeID("clippingPathInfo")).getInteger(stringIDToTypeID("clippingPathIndex"));
if (clippingPath != -1) {
loadPathAsSelection (clippingPath + 1);
expandSelection (12);
cropImage ();
}
else {};
};
function loadPathAsSelection (thePath) {
// =======================================================
var idsetd = charIDToTypeID( "setd" );
var desc1 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref1.putProperty( idChnl, idfsel );
desc1.putReference( idnull, ref1 );
var idT = charIDToTypeID( "T " );
var ref2 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref2.putIndex( idPath, thePath );
desc1.putReference( idT, ref2 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc1.putInteger( idVrsn, 1 );
var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );
desc1.putBoolean( idvectorMaskParams, true );
executeAction( idsetd, desc1, DialogModes.NO );
};
function expandSelection (theValue) {
// =======================================================
var idExpn = charIDToTypeID( "Expn" );
var desc3 = new ActionDescriptor();
var idBy = charIDToTypeID( "By " );
var idPxl = charIDToTypeID( "#Pxl" );
desc3.putUnitDouble( idBy, idPxl, theValue );
executeAction( idExpn, desc3, DialogModes.NO );
};
function cropImage () {
// =======================================================
var idCrop = charIDToTypeID( "Crop" );
var desc4 = new ActionDescriptor();
var idDlt = charIDToTypeID( "Dlt " );
desc4.putBoolean( idDlt, true );
executeAction( idCrop, desc4, DialogModes.NO );
};
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1199 Posts
  • 159 Reply Likes
Have you given a Scripting approach a try?
Photo of Tiemmothi

Tiemmothi

  • 12 Posts
  • 0 Reply Likes
nope, I may later tho. ATM I have no desire to script outside of the built in actions the adobe has given me. That and I have almost zero scripting But hey, I have an applescript that loads my servers and resets my workspace!!! woot.
Photo of christoph pfaffenbichler

christoph pfaffenbichler, Champion

  • 1199 Posts
  • 159 Reply Likes
And the one I had posted is no option?
Photo of Tiemmothi

Tiemmothi

  • 12 Posts
  • 0 Reply Likes
It might well be, but the whole.. no desire to script atm is the overriding factor.