Copy link to clipboard
Copied
I have a .jsx Photoshop script workflow that begins by first applying a Brightness/Contrast adjustment to the current image, then uses the "Auto" setting.
For the next step, I'd like to get the properties of that Brightness/Contrast layer, and then IF the brightness meets a certain criteria? Change the brightness to some other value. Same for the contrast.
What's the best way to automate this in my .jsx file?
Thanks!
Copy link to clipboard
Copied
You should be able to get the Layer’s settings via AM-code.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Any idea what that code would look like? I tried for HOURS yesterday and just couldn't get it to work. Kept throwing errors. Here's one I tried that outputs a Photoshop general error:
Copy link to clipboard
Copied
Any idea what that code would look like? I tried for HOURS yesterday and just couldn't get it to work. Kept throwing errors.
By @antond99983697
It would be better if you looked at the topics nearby or used the search.
Copy link to clipboard
Copied
adj.brightness is showing up as undefined when I run this function. Not sure why because the active layer should be a Brightness/Contrast layer.
Copy link to clipboard
Copied
// Apply auto brightness/contrast adjustment
var autoDescriptor = new ActionDescriptor();
var reference = new ActionReference();
reference.putClass(stringIDToTypeID("adjustmentLayer"));
autoDescriptor.putReference(stringIDToTypeID("null"), reference);
var typeDescriptor = new ActionDescriptor();
var brightnessDescriptor = new ActionDescriptor();
brightnessDescriptor.putBoolean(stringIDToTypeID("auto"), true);
brightnessDescriptor.putBoolean(stringIDToTypeID("useLegacy"), false);
typeDescriptor.putObject(stringIDToTypeID("type"), stringIDToTypeID("brightnessEvent"), brightnessDescriptor);
autoDescriptor.putObject(stringIDToTypeID("using"), stringIDToTypeID("adjustmentLayer"), typeDescriptor);
var resultDesc = executeAction(stringIDToTypeID("make"), autoDescriptor, DialogModes.NO);
///////////////////////////////////////////////////////////////////////////////////////////
// idle correction change so that photoshop removes the "auto" parameter from the adjustment object.
var d = new ActionDescriptor();
var r = new ActionReference();
r.putEnumerated(stringIDToTypeID("adjustmentLayer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
var data = new ActionDescriptor();
d.putObject(stringIDToTypeID("to"), stringIDToTypeID("brightnessEvent"), data);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);
///////////////////////////////////////////////////////////////////////////////////////////
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt')); // reference is active layer
var layerDesc = executeActionGet(ref);
var layerID = layerDesc.getInteger(stringIDToTypeID('layerID'));
// Use the function you found to get the brightness descriptor
var brConDesc = get_contrast_desc(layerID);
function get_contrast_desc(id) {
try {
var r = new ActionReference();
var d = new ActionDescriptor();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("json"));
r.putEnumerated(stringIDToTypeID("document"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("null"), r);
d.putInteger(stringIDToTypeID("layerID"), id);
d.putBoolean(stringIDToTypeID("layerInfo"), true);
d.putBoolean(stringIDToTypeID( "includeAncestors" ), false);
eval("var json="+executeAction(stringIDToTypeID("get"), d, DialogModes.NO).getString(stringIDToTypeID("json")));
var d = new ActionDescriptor();
if (!json.layers) return d;
if (json.layers.length != 1) return d;
if (json.layers[0].id != id) return d;
var adj = json.layers[0].adjustment;
alert(adj.brightness); // shows undefined, even though the active layer is a Brightness/Contrast layer
if (!adj) return d;
if (adj.brightness != undefined) d.putInteger(stringIDToTypeID("brightness"), adj.brightness);
if (adj.center != undefined) d.putInteger(stringIDToTypeID("center"), adj.center);
if (adj.useLegacy != undefined) d.putBoolean(stringIDToTypeID("useLegacy"), adj.useLegacy);
return d;
}
catch (e) { throw(e); }
}