Get code from foregroundColor

In my plugin I only set foreground and background colors, but never read them. I just tried to get them properly and it works only when you just open Ps or reset colors to default. But as soon as you change the color, RGBColor is meesed up and no way to get value. There was a bug reported here months ago, but nobody saw it (again, ping @kerrishotts). It appears it is set correctly only if you check one of RGB values in the picker before selecting:

Also, you need to set backgroundColor instead of background

Having said above, until bug is fixed (hopefully sooner rather than later :crossed_fingers:), I’d suggest using helper function to convert any other color to hex or just set directly (for example HSB). So you code would be:

const app = require('photoshop').app
document.querySelector('#btnColor').style.backgroundColor = `hsl(${app.foregroundColor.hsb.hue} ${app.foregroundColor.hsb.saturation}% ${app.foregroundColor.hsb.brightness}%)`;

I’d prefer LAB, because lightness and brightness (HSL vs HSB) are a bit different, but seems like LAB in UXP CSS is also not supported :confused:

I’ll also ping @amandah here just in case