Skip to main content
Inspiring
July 30, 2015
Answered

Change foreground color according to clipboard

  • July 30, 2015
  • 3 replies
  • 3432 views

Hi!

Is there a way to change the foreground color according to the clipboard contents?

In other words: let's say the clipboard contains ffdf00 (which is a yellow-ish color)

How can I copy that information and apply it to the foreground color in Photoshop so that I would now be painting in that yellow color?

This topic has been closed for replies.
Correct answer JJMack

I think you need to describe  how your using the clipboard the clipboard can contain many pixels and colors.

3 replies

Inspiring
August 2, 2015

JJ, what I mean is something simple like:

1. open notepad

2. type in 003576 (this is a dark blue color in Photoshop)

3. Highlight the above text (003576) and press ctrl+c, so it is now in the clipboard

4. write a Photoshop script which would be something like:

app.foregroundcolor = clipboard

..this way, when you run the script, the foreground color in Photoshop will change to #003576 without bringing up the color picker or any other input windows/dialogs

hope that makes sense

JJMack
Community Expert
Community Expert
August 2, 2015

Yes Text not Pixels can be pasted into fields and tools that use text input or have text option fields.  I often  paste text into the text tool.  So you should be able to paste text into the color picket dialog hex  input field.

However I do not know how one could use something like that in a script. The script would need to put the text into the clipboard first.  If the script knows the text it could just use it there would be no reason I can think of the would require the use of the clipboard.

JJMack
Inspiring
August 2, 2015

would something like this be of assistance? This script copies the active layer name to the clipboard (if you're running Win7):

app.system( "echo "   + activeDocument.activeLayer.name + " | CLIP");

I know there are several ways to copy information *to* the clipboard, but not *from* the clipboard, especially what I was trying to do here

Participating Frequently
July 31, 2015

I wrote this for you. Save it and add a keyboard shortcut to it. Then just copy and paste the color # into the dialog.

colorWin = new Window('dialog');

colorWin.alignChildren = 'right';

  colorWin.grp = colorWin.add('group');

  colorWin.grp.statHex = colorWin.grp.add('statictext', undefined, '#');

  colorWin.grp.fldHex = colorWin.grp.add('edittext');

  colorWin.grp.fldHex.active = true;

  colorWin.grp.fldHex.characters = 10;

  colorWin.btnOK = colorWin.add('button', undefined, 'OK');

  colorWin.btnOK.onClick = function() {

  colorWin.close();

  var hex = new SolidColor;

  hex.rgb.hexValue = colorWin.grp.fldHex.text;

  app.foregroundColor = hex;

  };

colorWin.center();

colorWin.show();

Inspiring
August 2, 2015

cbourn - first of all - thanks so much!! Awesome!! Does exactly what I needed. I can simply enter the color code into the dialog box now. Second - could there be a way to automate the process, so the script picks up the color code from the clipboard, then automatically pastes it into Photoshop, so it changes the foreground color automatically with no additional pop-up windows or having to manually type anything in?

Third - I meant to mark your reply as "correct answer" but mistakenly pressed it on JJ's reply- sorry. Thanks again, I'm keeping your script to do the trick!!!! Appreciated

JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
July 30, 2015

I think you need to describe  how your using the clipboard the clipboard can contain many pixels and colors.

JJMack