• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Copy foreground RGB values to clipboard

Participant ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

Hi, is there any know script that can take the foreground color of Photoshop and copy the RGB values to the clipboard? If not could someone savvy with scripting create one. I know a lot of user want this. Thanks

Views

3.9K

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

correct answers 1 Correct answer

Community Expert , Jun 23, 2019 Jun 23, 2019

Try this:

var doc = activeDocument;

var bR = foregroundColor.rgb.red;

var bG = foregroundColor.rgb.green;

var bB = foregroundColor.rgb.blue

var myColor = Math.round(bR) + ' ' + Math.round(bG) + ' ' + Math.round(bB);

var d = new ActionDescriptor(); 

d.putString(stringIDToTypeID("textData"), myColor); 

executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO); 

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

You can copy hex values. As far as actual rgb values, you can have a script get the numbers, but they would have to be combined in some form like comma separated values, which then would have to be broken apart to paste into different rgb fields.

Votes

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
Participant ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

I just want to grab them without having to open the color picker and select each field to copy them. If they were copied to the clipboard like this it would be fine.

255 170 210

68 199 255

Votes

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
Community Expert ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

How would you select what color to select?

Votes

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
Participant ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

I use Window and Mac. I mostly want this for Windows. I would just paste it into Notepad++ and select the color. Or I would save a text file and read them in as a varible parsing the value I want.

Votes

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
Participant ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

Votes

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
Community Expert ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

Also what OS are you using?

Votes

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
Community Expert ,
Jun 23, 2019 Jun 23, 2019

Copy link to clipboard

Copied

Try this:

var doc = activeDocument;

var bR = foregroundColor.rgb.red;

var bG = foregroundColor.rgb.green;

var bB = foregroundColor.rgb.blue

var myColor = Math.round(bR) + ' ' + Math.round(bG) + ' ' + Math.round(bB);

var d = new ActionDescriptor(); 

d.putString(stringIDToTypeID("textData"), myColor); 

executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO); 

Votes

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
Participant ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Wow, you can... thanks you so much. This is super helpful. I am loving this already it makes selecting a lot of colors through out the day a dream. I see a user up voted it as helpful the minute you posted it last night. I think many user will find this helpful. Thank you so much again!!!

Votes

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
Participant ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

This is so great I might be on my way to creating scripts as helpful as Chucks someday. This is why examples can be a wealth when a user like Chuck lends a hand. What I was currently working with was asking for RGB values. However, I forgot that most times I want the hex value because I am working in things like HTML, CSS, JavaScript, Adobe Animate, and Adobe Dreamweaver and many others. So, referring Chuck's gracious code I then tracked down this document. I search around for syntax like Chuck"s code to get the property I am looking for. That property being hexValue. So I extended this script just a little to also grab the hex value. I don't think I need any function like Math.round() wrapped around it because it stated the type was a string. I works well this is a dream!!! and thank you again Chuck!

var doc = activeDocument; 

 

var bR = foregroundColor.rgb.red; 

var bG = foregroundColor.rgb.green; 

var bB = foregroundColor.rgb.blue;  

var bx = foregroundColor.rgb.hexValue;

 

var myColor = Math.round(bR) + ' ' + Math.round(bG) + ' ' + Math.round(bB) + ' ' + bx; 

 

var d = new ActionDescriptor();   

d.putString(stringIDToTypeID("textData"), myColor);   

executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO);

To anybody that wants to understand how to use it. Put the code in text file in a text editor. Don't use things like MS Word that add formatting to the text. Use a text specific editor. Save the file any name you want with the .jsx extension. The find your scripts directory in you Adobe Photoshop folder. For example mine live at

C:\Program Files\Adobe\Adobe Photoshop CC 2019\Presets\Script

Then drop the save file with the .jsx file extension in there (eg filename PsdRgbh2Txt.jsx) . Relaunch Photoshop, and it should work.

Votes

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
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Glad it worked well for you.

Votes

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
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

However, I forgot that most times I want the hex value because I am working in things like HTML, CSS, JavaScript, Adobe Animate, and Adobe Dreamweaver and many others

You might also want to consider the color profile of the hex value. For matching color appearance in HTML code you would want the document profile to be sRGB. That might not be a problem if you know your documents are always assigned sRGB, but ensuring sRGB can also be scripted.

This line before your color value code would check the document assignment, and if it's not sRGB make a conversion:

if (app.activeDocument.colorProfileName!="sRGB IEC61966-2.1"){

     doc.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, true);

     //to assign use this

     //doc.colorProfileName="sRGB IEC61966-2.1";

}

Votes

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
Participant ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

OK, also very helpful. I see what you mean. Thanks

Votes

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
Explorer ,
Jul 10, 2020 Jul 10, 2020

Copy link to clipboard

Copied

LATEST

Good night.

How do you think I would be able to do the same, to paste the colors in CMYK too, and that would work in Illustrator too?

Votes

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