[Scripting] set showColorPicker() default color?

Community Beginner ,
Sep 02, 2020 Sep 02, 2020

Copy link to clipboard

Copied

I am looking for a way to set the default color when the color picker is opened, ideally one that doesn't update the foreground color first, which was my original solution. The extension I am building uses some color inputs, which when clicked, should open the color picker with whatever the current color input value is. 

 

The foreground color solution worked, but I noticed that if you update the foreground color with a solid color layer selected, it updates the solid color layer aswell.

 

TOPICS
Actions and scripting

Views

72

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 22, 2022 Jul 22, 2022

Copy link to clipboard

Copied

LATEST

HI

I meet the same issue and search all the net without success.

finally i figure out my self with a better way using ActionDescriptor .

you can set a default selected color in the ColorPicker and even change the title of the dialog

function selectColorPicker(defaultColor, title) {
    var ref1 = new ActionReference();
        ref1.putClass(stringIDToTypeID('application'));

    var desc9 = new ActionDescriptor();
        desc9.putDouble( charIDToTypeID( "Rd  " ), defaultColor.red);
        desc9.putDouble( charIDToTypeID( "Grn " ), defaultColor.green);
        desc9.putDouble( charIDToTypeID( "Bl  " ), defaultColor.blue);

    var desc = new ActionDescriptor();
        desc.putReference(stringIDToTypeID('null'), ref1);
        desc.putObject( charIDToTypeID( "Clr " ), charIDToTypeID( "RGBC" ), desc9 );
        desc.putString(stringIDToTypeID("context"), title);

    var result = app.executeAction(app.stringIDToTypeID('showColorPicker'), desc, DialogModes.NO);

    var RGBFloatColor = result.getObjectValue(stringIDToTypeID('RGBFloatColor'));
    var red = RGBFloatColor.getDouble(stringIDToTypeID("red"));
    var green = RGBFloatColor.getDouble(stringIDToTypeID("grain"));
    var blue = RGBFloatColor.getDouble(stringIDToTypeID("blue"));

    return {red: red, green: green, blue: blue}
}


var newColor = selectColorPicker({red: 128, green: 128, blue: 128}, "my custom color picker");
$.writeln(JSON.stringify(newColor));

 

hope it helps

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines