Skip to main content
Participating Frequently
February 19, 2025
Question

If action for 1 person or 2 person

  • February 19, 2025
  • 3 replies
  • 344 views

I need an if action to seperate pictures. If there is 1 person at the photo I want to use FİRST ACTİON, if there is 2 person I want to use SECOND ACTİON. How can I do it with Photoshop 2025.

I will add an ATN folder here and 2 photo.

please change 8bf to atn.

  

3 replies

c.pfaffenbichler
Community Expert
Community Expert
February 20, 2025

To perform an Action from a Script use 

app.doAction("actionname", "setname")

and replace actionname and setname with the names of the Action you want to run and the name of the set in which that Action resides. 

Participating Frequently
February 21, 2025

How Can I choose to use action 1 person or 2 person with if command. I tried but I failed.

c.pfaffenbichler
Community Expert
Community Expert
February 21, 2025

Insert the code I mentioned earlier (app.doAction …) in the if-, respectively else-clause: 

 

if (theCounter == 1) {alert (theCounter+" person")}
else {alert (theCounter+" persons")};

 

 

c.pfaffenbichler
Community Expert
Community Expert
February 19, 2025

More than two persons would necessitate something different (edit: one could for example determine one face, fill that area, try to determine another face, fill that area etc. until no further faces can be located) but please give this a try: 

 

Edited code 2025-02-20

// determine how many persons can be identified in the image;
// 2025, use it at your own risk;
if (app.documents.length > 0) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.togglePalettes();
var theCopy = activeDocument.duplicate("theCopy", true);
var theLayer = theCopy.layers[0];
////////////////////////////////////
var theCheck = true;
var theCounter = 0;
while (theCheck == true) {
try {
var newLayer = theCopy.activeLayer.duplicate();
theCopy.activeLayer = newLayer;
facialLiquify01 ();
newLayer.blendMode = BlendMode.DIFFERENCE;
mergVisibleToNewLayer ();
var newerLayer = theCopy.activeLayer;
applyThreshold(1);
newerLayer.applyMaximum(30);
useMagicWand2022([1,1]);
theCopy.selection.invert();
makeWorkPath(0);
var thePath = theCopy.pathItems[theCopy.pathItems.length-1];
thePath.name = "face_"+String(theCounter);
theCounter++;
newerLayer.remove();
newLayer.remove();
thePath.makeSelection(0, false, SelectionType.REPLACE);
thePath.deselect();
theCopy.selection.fill(app.foregroundColor);
theCopy.selection.deselect();
} catch (e) {theCheck = false}
};
////////////////////////////////////
theCopy.close(SaveOptions.DONOTSAVECHANGES);
if (theCounter == 1) {alert (theCounter+" person")}
else {alert (theCounter+" persons")};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
app.togglePalettes();
};
////// face liquify //////
function facialLiquify01 () {
// =======================================================
var idLqFy = charIDToTypeID( "LqFy" );
    var desc225 = new ActionDescriptor();
    var idLqMe = charIDToTypeID( "LqMe" );
    var idfaceMeshData = stringIDToTypeID( "faceMeshData" );
    desc225.putData( idfaceMeshData, String.fromCharCode( 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 77, 101, 115, 104, 0, 0, 0, 3, 0, 0, 0, 21, 102, 97, 
99, 101, 68, 101, 115, 99, 114, 105, 112, 116, 111, 114, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 15, 102, 
97, 99, 101, 77, 101, 115, 104, 86, 101, 114, 115, 105, 111, 110, 108, 111, 110, 103, 0, 0, 0, 2, 0, 0, 0, 12, 102, 97, 99, 101, 73, 110, 
102, 111, 76, 105, 115, 116, 86, 108, 76, 115, 0, 0, 0, 1, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 8, 102, 97, 99, 101, 
73, 110, 102, 111, 0, 0, 0, 3, 0, 0, 0, 10, 102, 97, 99, 101, 67, 101, 110, 116, 101, 114, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 
0, 0, 0, 0, 110, 117, 108, 108, 0, 0, 0, 2, 0, 0, 0, 0, 88, 32, 32, 32, 100, 111, 117, 98, 63, 228, 159, 82, 77, 210, 241, 170, 
0, 0, 0, 0, 89, 32, 32, 32, 100, 111, 117, 98, 63, 201, 108, 29, 90, 203, 111, 70, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 
97, 108, 117, 101, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 13, 102, 101, 97, 116, 117, 114, 101, 86, 97, 108, 117, 101, 115, 
0, 0, 0, 4, 0, 0, 0, 9, 102, 97, 99, 101, 87, 105, 100, 116, 104, 100, 111, 117, 98, 191, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
10, 99, 104, 105, 110, 72, 101, 105, 103, 104, 116, 100, 111, 117, 98, 191, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 106, 97, 119, 83, 104, 
97, 112, 101, 100, 111, 117, 98, 191, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 102, 111, 114, 101, 104, 101, 97, 100, 72, 101, 105, 103, 104, 
116, 100, 111, 117, 98, 191, 240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 99, 101, 
109, 101, 110, 116, 115, 79, 98, 106, 99, 0, 0, 0, 1, 0, 0, 0, 0, 0, 20, 102, 101, 97, 116, 117, 114, 101, 68, 105, 115, 112, 108, 97, 
99, 101, 109, 101, 110, 116, 115, 0, 0, 0, 0 ) );
executeAction( idLqFy, desc225, DialogModes.NO );
};
////// make work path from selection //////
function makeWorkPath (theTolerance) {
// =======================================================
var idMk = charIDToTypeID( "Mk  " );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
ref3.putClass( idPath );
desc5.putReference( idnull, ref3 );
var idFrom = charIDToTypeID( "From" );
var ref4 = new ActionReference();
var idcsel = charIDToTypeID( "csel" );
var idfsel = charIDToTypeID( "fsel" );
ref4.putProperty( idcsel, idfsel );
desc5.putReference( idFrom, ref4 );
var idTlrn = charIDToTypeID( "Tlrn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5.putUnitDouble( idTlrn, idPxl, theTolerance );
executeAction( idMk, desc5, DialogModes.NO );
/// get index;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("itemIndex"));
ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var pathDesc = executeActionGet(ref);
// return index;
return pathDesc.getInteger(stringIDToTypeID("itemIndex"))
};
////// use magic wand tool //////
function useMagicWand2022 (theCoord) {
var idnull = charIDToTypeID( "null" );
var idPxl = charIDToTypeID( "#Pxl" );
// select tool;
var desc2 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putClass( stringIDToTypeID( "magicWandTool" ) );
desc2.putReference( idnull, ref2 );
desc2.putBoolean( stringIDToTypeID( "dontRecord" ), true );
desc2.putBoolean( stringIDToTypeID( "forceNotify" ), true );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// apply tool;
var desc2 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );
desc2.putReference( idnull, ref2 );
var desc3 = new ActionDescriptor();
desc3.putUnitDouble( charIDToTypeID( "Hrzn" ), idPxl, theCoord[0] );
desc3.putUnitDouble( charIDToTypeID( "Vrtc" ), idPxl, theCoord[1] );
desc2.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Pnt " ), desc3 );
desc2.putInteger( charIDToTypeID( "Tlrn" ), 30 );
desc2.putBoolean( charIDToTypeID( "AntA" ), true );
desc2.putBoolean( stringIDToTypeID("merged"), true);
executeAction( charIDToTypeID( "setd" ), desc2, DialogModes.NO );
};
////// layer via copy //////
function mergVisibleToNewLayer (){
var desc23 = new ActionDescriptor();
desc23.putBoolean( stringIDToTypeID( "duplicate" ), true );
executeAction( stringIDToTypeID( "mergeVisible" ), desc23, DialogModes.NO );
};
////// apply threshold //////
function applyThreshold (theValue) {
var desc232 = new ActionDescriptor();
desc232.putInteger( stringIDToTypeID( "level" ), theValue );
executeAction( stringIDToTypeID( "thresholdClassEvent" ), desc232, DialogModes.NO );
};

 

 

 

c.pfaffenbichler
Community Expert
Community Expert
February 19, 2025

I think @jazz-y utilized Liquify 

to identify the position of a face in an image; it might be possible to adapt that to »process« more than one face and use that result to make the determination. 
 
I am afraid Camera Raw’s auto maks might be even harder to utilize.