0

I have made this function into a JS file...

function getColors(isPick, isForecolor)
{
    var chosenFunction = 'getColor(' + isPick + ', ' + isForecolor + ')';
    csInterface.evalScript(chosenFunction, function(result)
    {
        if(result !== 'undefined')
        {
            if (isForecolor == true){
                foregroundHexColor = result;
                // etc...
            }
            else
            {
                backgroundHexColor = result;
                //etc..
            };
        };
    });
};

which get a hexadecimal color value from this function from a JSX file.

function getColor(isPick, isForecolor)
{
    var color_PickerCase;
    var decimal_Color;
    var hexadecimal_Color;

    if (isForecolor == true)
    {
        color_PickerCase = app.foregroundColor.rgb.hexValue;
    }
    else
    {
        color_PickerCase = app.backgroundColor.rgb.hexValue;
    };

    if (isPick == true)
    {
        if (app.showColorPicker(isForecolor)){
            decimal_Color = color_PickerCase;
            hexadecimal_Color = decimal_Color.toString(16);
        }
        else
        {
            return;
        };
    }
    else
    {
        decimal_Color = color_PickerCase;
        hexadecimal_Color = decimal_Color.toString(16);
    };

    return hexadecimal_Color;    
};

In some way it works, but for some reason I have to do the same thing two times so to get the value!!! Any idea why is this happening?

Thank you for your time!!!

UPDATE: A correction, it works only at first click. Then needs to clicked two times so to get the value!!!

1

You are asking for the color before picking. Thus you get the color form the last time you picked ;)

Anyway your code can be made better

function getColor(isPick, isForecolor)
{
    var color_PickerCase;
    var decimal_Color;
    var hexadecimal_Color;


    // note according to docs showColorPicker 
    // does not accept any parameters
    if (isPick === true && app.showColorPicker() === false)
    {
            return; // maybe throw an error? 
    }

    if (isForecolor === true)
    {
        color_PickerCase = app.foregroundColor.rgb.hexValue;
    }
    else
    {
        color_PickerCase = app.backgroundColor.rgb.hexValue;
    }

    decimal_Color = color_PickerCase;
    hexadecimal_Color = decimal_Color.toString(16);
    return hexadecimal_Color;    
};
  • Thank you very much my friend, it worked!!! I just had to add the isForecolor variable into app.showColorPicker() like this app.showColorPicker(isForecolor), so to understands if color picker will open for foreground or background color!!! Change it at your answer if you like so to be totally correct!!! Thank you again!!! :) – Simonetos The Greek Oct 27 '19 at 8:41
  • You wrote that according to docs, showColorPicker does not accept any parameters... Please take a look here. – Simonetos The Greek Oct 28 '19 at 15:35
  • 1
    @SimonetosTheGreek i know but adobes official documentation does not mention it. The danger is that they may remove undocumented functionality. – joojaa Oct 28 '19 at 17:33

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.