Copy link to clipboard
Copied
Hi, I'm not too good at scripting, so looking for some help.
I would like to get let the user to select a point of the image, then I would need to set variables to the location of the sample point and also collect the RGB Values as variables too.
I've used the script listening but not too sure how to gather that information.
I also like to use it back with applescript that I can follow.
Many Thanks
Matt
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Great thanks, I can't get that to return the RGB Values to applescript or the Alert in JS to display them.
tell application id "com.adobe.photoshop"
activate
set RGBValue to do javascript "#target photoshop var doc = app.activeDocument, samps = doc.colorSamplers; for ( var i = 0; i < samps.length; i++ ) { var r = Math.round( samps.color.rgb.red ), g = Math.round( samps.color.rgb.green ), b = Math.round( samps.color.rgb.blue ); return( r+g+b ); } alert ( samps[1].position ); "
log RGBValue
end tell
Copy link to clipboard
Copied
I found another example similar to the above that works. But I need to get the previously selected color sample from the image rather than one defined in the code.
tell application id "com.adobe.photoshop"
activate
set RGBValue to (do javascript "#target photoshop
function getRGB (){
// Define the x and y coordinates for the pixel to sample.
var x = 1;
var y = 1;
// Add a Color Sampler at a given x and y coordinate in the image.
var pointSample = app.activeDocument.colorSamplers.add([(x - 1),(y - 1)]);
// Obtain array of RGB values.
var rgb = [
Math.round(pointSample.color.rgb.red),
Math.round(pointSample.color.rgb.green),
Math.round(pointSample.color.rgb.blue)
];
// Obtain array of rounded CMYK values.
var cmyk = [
Math.round(pointSample.color.cmyk.cyan),
Math.round(pointSample.color.cmyk.magenta),
Math.round(pointSample.color.cmyk.yellow),
Math.round(pointSample.color.cmyk.black)
];
// Remove the Color Sampler.
//pointSample.remove();
// Display the complete RGB values and each component color.
return(rgb);}
getRGB()
")
end tell
set AppleScript's text item delimiters to {","}
set RValue to 1st text item of RGBValue
set GValue to 2nd text item of RGBValue
set BValue to 3rd text item of RGBValue