Color picker return error - RGBFloatColor uses 'grain' label instead of 'green'

Hello, I am developing a UXP plugin that allows the user to open the Photoshop color-picker and select a color, and I have found an error in the data structure returned when the colour-picker is closed. I have found that the RGBFloatColor value returned from the color-picker uses the label ‘grain’ instead of ‘green’ in the RGB values. A search for the term ‘grain’ in the Photoshop source code would likely find the word quickly. My code is currently only able to use the green value from the RGBFloatColor by calling the ‘grain’ label - Below is some UXP debugger code and console output that should show the issue. As this will obviously break any plugin once it is found and fixed later, could Adobe please check this and update their code? Thank you.

sample code for UXP debugger below (obviously the return red, green, blue values will differ depending on the color you have chosen)

const ps = require(‘photoshop’);
const executeAsModal = ps.core.executeAsModal;
await executeAsModal(async () => {
// In the modal state now
const openPicker = {
_target: { _ref: “application” },
_obj: “showColorPicker”,
context: “Some title for the color picker…”,
color: {
_obj: ‘RGBColor’,
red: 0,
green: 0,
blue: 0,

const res = await ps.action.batchPlay([openPicker], {})

for (const [key, value] of Object.entries(res[0].RGBFloatColor))
console.log(${key}: ${value});

}, {commandName: “Select Color”})

after making a new color selection and closing the color picker, the output to the console is…
_obj: RGBColor
red: 0
grain: 0 ← ERROR - NOTE ‘GRAIN’
blue: 0

It’s a leftover from pre-UXP times. both green and grain used to be grn, that’s why you can pass any of those two values (I think :thinking:), but response will always be grain. Maybe some day this will get fixed

1 Like

there are more like these… in an ideal case you could use DOM to avoid dealing with batchPlay at all and have some reasonable names and arguments.

1 Like

Interesting comments on this page.

I tried to fix once but there was too much “legacy” code and everyone voted to leave it alone…sorry.

Yea…since Tom Ruark gave up on fixing this back in 2016 I wouldn’t expect it to be fixed in the near future :grin:

1 Like

Thanks everyone for your help with this - quite the insight when you go scratching below the surface a little bit. In the end I found I could not access the ‘grain’ entry simply as ‘green’ as the green label is NOT converted and my Grn value is initialised to NaN.

I ended up using an if-conditional asking…
if(‘grain’ in res[0].RGBFloatColor){ Grn = res[0].RGBFloatColor.grain }
else if(‘green’ in res[0].RGBFloatColor){ Grn = res[0] }

I’ve also noticed if you select one of the Lab display options in the color-picker before making a Color selection, the return label is neither ‘grain’ or ‘green’ but is instead ‘greenFloat’ - which I also have to check for and multiply by 255.


Grn = res[0].RGBFloatColor?.grain ?? res[0].RGBFloatColor?.green ?? null

Thanks for that - I know the ternary operator ?: but I’m not familiar with that syntax - I’ll drop it in and see how it goes