Converting eyedropper's 'gray' value to RGB

I am listening to Photoshop’s set event for the Eye Dropper Tool. When using it with a Mask, it returns an object with the color mode grayscale and a value called gray. I need to convert this value to an RGB or Hex value.

For example, in the Color Panel, it says I have picked the gray color 50% which has an RGB value of ((149, 149, 149) and a Hex value of #959595.

I am unable to get the RGB & Hex values correctly. The formula I’m currently using is

let gray = parseInt(255-(255*obj.gray/100));

Using the above 50% example, gray is 49.8 and does not returning the correct result.

It works out as this…

gray = 255-(255*49.8/100)
gray = 255-(255*0.498)
gray = 255-126.99
gray = 128.01

128 is pretty far off from the RGB value of 149 shown in the Photoshop picker (that would be the correct value if the mode was HSB & B was 50%).

How can I convert the Photoshop eye dropper gray value to the same RGB/Hex Photoshop’s picker is showing?

Thank you!

Using the Alchemist plugin, I inspected the Application object and found a property called foregroundColorRGB. Here’s the code for getting it:

const get_fg_color = () => {
  const batchPlay = require("photoshop").action.batchPlay;
  const result = batchPlay(
        "_obj": "get",
        "_target": [
              "_ref": "application",
              "_enum": "ordinal",
              "_value": "targetEnum"
        "_options": {
           "dialogOptions": "dontDisplay"
     "synchronousExecution": true,
     "modalBehavior": "fail"
  return result[0].foregroundColorRGB;

It would be nice to know why the gray amount from the set event is different, but getting the RGB value after the FG color was set solved my issue.