# Problem with colorpicker

**URL:** <https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754>\
**Category:** UXP Plugin API\
**Created:** [April 6, 2021, 11:20am UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754 "2021-04-06T11:20:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![svumme](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/svumme/32/1289_2.png) [@svumme](https://forums.creativeclouddeveloper.com/u/svumme)\
**Post date:** [April 6, 2021, 11:20am UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/1 "2021-04-06T11:20:20Z")

</div>

Good day, i might be making a mistake somewhere but if not this is a bug,  
i’d like to get LAB values from the colorpicker with this code:

const picker2 =async () =\> {  
const result = await batchPlay(  
[  
{  
"\_obj": "showColorPicker",  
"application": {  
"\_class": "null"  
},  
"value": true,  
"color": {  
"\_obj": "labColor",  
"luminance": 100,  
"a": 35,  
"b": 0  
},  
"RGBFloatColor": {  
"\_obj": "RGBColor",  
"red": 255,  
"grain": 229.52720046043396,  
"blue": 255  
},  
"dontRecord": true,  
"forceNotify": true,  
"\_isCommand": false,  
"\_options": {  
"dialogOptions": "dontDisplay"  
}  
}  
],{  
"synchronousExecution": false,  
"modalBehavior": "fail"  
});  
labvalue=result[0].color  
return labvalue  
}

but it only works if the selector is set to LAB.

 ![lab](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/3/35eb03cafd09d9660f1eef267bf070544457290a.png)

If the selector is in RGB i cannot get LAB values.  
If i wanted to get RGB values it works on any selector setting.

---

<div class="post-metadata">

**Author:** ![Pierre\_G](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pierre_g/32/971_2.png) [@Pierre\_G](https://forums.creativeclouddeveloper.com/u/Pierre_G)\
**Post date:** [April 6, 2021, 12:20pm UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/2 "2021-04-06T12:20:25Z")

</div>

Ciao!

Try this:

```
async function colorPicker() {
    var colorPicked = await batchPlay(
        [{
            "_obj": "showColorPicker",
            "application": {
                "_class": "null"
            },
            "value": true,
            "color": {
                "_obj": "labColor",
                "luminance": 100, // starting value in Lab
                "a": 35,
                "b": 0
            },
            "dontRecord": true,
            "forceNotify": true,
        }], {
            "synchronousExecution": true,
            "modalBehavior": "fail"
        })[0].color;

    console.log("You picked:", colorPicked); // show picked color in whatever color mode : RGB. Lab, HSB
    return colorPicked;
}
```

---

<div class="post-metadata">

**Author:** ![svumme](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/svumme/32/1289_2.png) [@svumme](https://forums.creativeclouddeveloper.com/u/svumme)\
**Post date:** [April 6, 2021, 5:09pm UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/3 "2021-04-06T17:09:08Z")

</div>

@Pierre_G it’s still not working, here i executed the code and memorized it in a variable and as you can see it recalls only RGB values if the radio button is on RGB.

 ![pierre](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/0/0596d07d4b389b8cf50aa31e899b010cd55a6375.png)

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [April 6, 2021, 11:00pm UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/4 "2021-04-06T23:00:33Z")

</div>

You can use Photoshop’s internal method to convert colors from one color space to another:

```
export function convertColorSpace(color: Color | PsColor, colorSpace: 'RGB' | 'HSB' | 'CMYK' | 'grayscale' | 'lab'): PsColor {
  const desc = {
    _obj: "convertColorToSpace",
    _target: { _ref: "application" },
    color,
    colorSpace: {
      _enum: "colorSpace",
      _value: colorSpace
    }
  }
  return photoshop.action.batchPlay([desc], { synchronousExecution: true })[0].color
}

```

`console.log(convertColorSpace({_obj: 'RGBColor', red: 255, green:0, blue: 0}, "lab"))`

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/f/f486e13874a3c1cd006ef4f68c3833da657ebc4c.png)

---

<div class="post-metadata">

**Author:** ![Pierre\_G](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pierre_g/32/971_2.png) [@Pierre\_G](https://forums.creativeclouddeveloper.com/u/Pierre_G)\
**Post date:** [April 6, 2021, 11:16pm UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/5 "2021-04-06T23:16:06Z")

</div>

Here you go, a Luminosity picker:

```
async function lumaPicker() {
  const batchPlay = require("photoshop").action.batchPlay;
  var colorPicked = await batchPlay(
    [{
      "_obj": "showColorPicker",
      "application": {
        "_class": "null"
      },
      "value": true,
      "color": {
        "_obj": "labColor",
        "luminance": 100, // starting color values in Lab
        "a": 35,
        "b": 0
      },
      "dontRecord": true,
      "forceNotify": true,
    }], {
      "synchronousExecution": true
    })[0].color;

  var labLuma = await batchPlay([{
    "_obj": "convertColorToSpace",
    "_target": {
      "_ref": "application"
    },
    "color": colorPicked, // color object
    "colorSpace": {
      "_enum": "colorSpace",
      "_value": "lab"
    }
  }], {
    "synchronousExecution": true,
  })[0].color.luminance;

   
  console.log("You picked Luma =", Math.round(labLuma));
}
```

---

<div class="post-metadata">

**Author:** ![svumme](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/svumme/32/1289_2.png) [@svumme](https://forums.creativeclouddeveloper.com/u/svumme)\
**Post date:** [April 7, 2021, 11:50am UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/6 "2021-04-07T11:50:21Z")

</div>

Thank you so very much @Pierre_G and @simonhenke , you are too kind, this way you fixed and bypassed the issue i had! I do however imagine this to be a UXP bug that needs fixing, considering that in extendscript there was no need for further color conversion.  
Have a nice day.

---

<div class="post-metadata">

**Author:** ![DavideBarranca](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidebarranca/32/1523_2.png) [@DavideBarranca](https://forums.creativeclouddeveloper.com/u/DavideBarranca)\
**Post date:** [April 13, 2021, 9:33am UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/7 "2021-04-13T09:33:31Z")

</div>

Hi, where the heck is `convertColorToSpace` ever mentioned?!  
Thanks!

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [April 13, 2021, 10:11am UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/8 "2021-04-13T10:11:35Z")

</div>

It was somewhere buried in the prerelease forum… One of the many things that should be documented but aren’t 🤔  
IMO such scripts would be perfect for the “How do I…” section in the docs.

---

<div class="post-metadata">

**Author:** ![Jarda](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/jarda/32/1909_2.png) [@Jarda](https://forums.creativeclouddeveloper.com/u/Jarda)\
**Post date:** [April 13, 2021, 1:26pm UTC](https://forums.creativeclouddeveloper.com/t/problem-with-colorpicker/2754/9 "2021-04-13T13:26:02Z")

</div>

Until you get DOM where this will be easy to do.
