Skip to main content
Participant
December 27, 2022
Answered

how can i copy hex code when i just open the color piker?

  • December 27, 2022
  • 3 replies
  • 1107 views

in photoshop, when i try to copy some hex code, and show up the colour piker, my text box is in betwen the 'c'. so i shoud move my mouse to copy hex code. before, my text box was in hex code so that i can copy easy but now it take so much time. i try reset my photoshop setting but nothing shange.

This topic has been closed for replies.
Correct answer Conrad_C

What color mode is the document using? When I try it, the default field depends on the document’s color mode. When the document mode is set to Lab Color, the default field is L. For CMYK Color, the default field is C. When set to RGB Color, the default field is hexadecimal. I never noticed this before.

 

 

3 replies

Stephen Marsh
Community Expert
Community Expert
December 27, 2022

@asdadw – For me, the hex field is always highlighted when entering the colour picker, no matter whether one of the HSB, RGB, Lab or CMYK fields was previously used. I'm on a Mac and have tested in multiple versions and the behaviour is the same.

 

A script could be written to copy the foreground colour picker value to the clipboard as hex values, without opening the colour picker window. This could be accessed via a keyboard shortcut.

 

You could paste your Help > System Info into a reply, that might help pinpoint the issue.

Stephen Marsh
Community Expert
Community Expert
December 27, 2022

@asdadw – whether or not you wanted/needed a script to copy as hex to the clipboard, this was an exercise for me more than anything.

 

The following two scripts will copy the foreground colour as a hex value to the clipboard. I have commented the code to add/remove various formatting options.

 

This script uses UPPERCASE without the # prefix:

 

/* Based on - https://forums.adobe.com/thread/2632707 */

#target photoshop

var RGB2HEX = foregroundColor.rgb.hexValue;
//var RGB2HEX = "#" + foregroundColor.rgb.hexValue;
//var RGB2HEX = foregroundColor.rgb.hexValue.toLowerCase();
//var RGB2HEX = "#" + foregroundColor.rgb.hexValue.toLowerCase();

var d = new ActionDescriptor();
d.putString(stringIDToTypeID("textData"), RGB2HEX);
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO);

 

While this script copies to the clipboard in lowercase with the # prefix:

 

/* Based on - https://gist.github.com/Arahnoid/9923989 */
var fR = Math.floor(app.foregroundColor.rgb.red);
var fG = Math.floor(app.foregroundColor.rgb.green);
var fB = Math.floor(app.foregroundColor.rgb.blue);

rgbToHex(fR, fG, fB);

function rgbToHex(r, g, b) {
    var theHex = "#" + ((1 << 24) + (r << 16) + (g <<  + b).toString(16).slice(1);
    //var theHex = ((1 << 24) + (r << 16) + (g <<  + b).toString(16).slice(1);
    // theHex = theHex.toUpperCase();
    
    var d = new ActionDescriptor();
    d.putString(stringIDToTypeID("textData"), theHex);
    executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

 

Conrad_C
Community Expert
Conrad_CCommunity ExpertCorrect answer
Community Expert
December 27, 2022

What color mode is the document using? When I try it, the default field depends on the document’s color mode. When the document mode is set to Lab Color, the default field is L. For CMYK Color, the default field is C. When set to RGB Color, the default field is hexadecimal. I never noticed this before.

 

 

Stephen Marsh
Community Expert
Community Expert
December 27, 2022

@Conrad_C – Good point, I was testing in RGB docs and can confirm your results!

Jeff Arola
Community Expert
Community Expert
December 27, 2022

What version of photoshop and windows are you using?