0

I am using this script bellow to get an RGB color from color picker. Any idea how can I do the same thing but using Photoshop's color piker instead of system's one?

var hexToRGB = function(hex) {
    var r = hex >> 16;
    var g = hex >> 8 & 0xFF;
    var b = hex & 0xFF;
    return [r, g, b];
};

var color_decimal = $.colorPicker();
var color_hexadecimal = color_decimal.toString(16);
var color_rgb = hexToRGB(parseInt(color_hexadecimal, 16));

I have found something like this, var cP = app.showColorPicker();, but it just returns a boolean value...

PS: Newbie to Photoshop scripting!!!

2

app.showColorPicker(); returns true if OK button was clicked and false if it was cancelled. To get the selected color simply get a foreground color after color picker window was closed:

var myColor = getColorpickerColor(); 

if (myColor !== false) alert(myColor.rgb.hexValue);

function getColorpickerColor()
{
    if (app.showColorPicker())
    {
        return app.foregroundColor
    }
    else
    {
        return false
    }
}; // end of getColor()
  • I did a test as it is and I got this ... "Illegal 'return' of a function body"!!! – Simonetos The Greek Jun 24 at 10:56
  • 1
    well, return only can be used inside of a function. I updated my answer – Sergey Kritskiy Jun 24 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.