set dark, gray, light points on curve from available color sample at specific coordinates by script
Hi everyone,
i want to create photoshop script to set black point, white point, gray point on the curve from available color sample at specific position on image.
set "black point" of curve from color sample at position x=1000, y=40
set "gray point" of curve from color sample at position x=1000, y=500
set "white point" of curve from color sample at position x=1000, y=960
i tried a program but it doesn't seem to work. my photoshop version is 25.12
please guide me, I appreciate your help.

#target photoshop
function setCurvePoints() {
var doc = app.activeDocument;
// Get color sample values at specified positions
var blackPointSample = getColorSample(1000, 40);
var grayPointSample = getColorSample(1000, 500);
var whitePointSample = getColorSample(1000, 960);
// Create a new Curves adjustment layer
var idCurves = stringIDToTypeID("Curves");
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putClass(idCurves);
desc.putReference(charIDToTypeID("null"), ref);
executeAction(charIDToTypeID("Mk "), desc, DialogModes.NO);
var adjustmentLayer = doc.activeLayer;
// Set the black point
setCurvePoint(adjustmentLayer, blackPointSample, [0, 0]);
// Set the white point
setCurvePoint(adjustmentLayer, whitePointSample, [255, 255]);
// Set the gray point
setCurvePoint(adjustmentLayer, grayPointSample, [128, 128]);
alert("Curves adjustment points have been set.");
}
// Get color sample at specified position
function getColorSample(x, y) {
var samplePoint = [x, y];
var colorSampler = app.activeDocument.colorSamplers.add(samplePoint);
var colorSample = colorSampler.color.rgb;
colorSampler.remove();
return colorSample;
}
// Set a point on the Curves adjustment layer
function setCurvePoint(layer, colorSample, targetPoint) {
try {
var idCurves = stringIDToTypeID("curves");
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("AdjL"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
desc.putReference(charIDToTypeID("null"), ref);
var list = new ActionList();
var curvePoint = new ActionDescriptor();
curvePoint.putEnumerated(charIDToTypeID("Chnl"), charIDToTypeID("Chnl"), charIDToTypeID("RGB "));
curvePoint.putDouble(charIDToTypeID("Icnt"), targetPoint[0]);
curvePoint.putDouble(charIDToTypeID("Otpt"), targetPoint[1]);
list.putObject(idCurves, curvePoint);
desc.putList(charIDToTypeID("Adjs"), list);
executeAction(idCurves, desc, DialogModes.NO);
} catch (e) {
alert("Error setting curve point: " + e.message);
}
}
setCurvePoints();


