1

I was wondering if it is possible for a photoshop action to choose foreground or background color from the swatch. I have tried doing it, but instead of picking from swatch it is always taking a fixed value. I am trying the script to pick color from the swatch sequentially. For example, if there are 5 colors in the swatch, it should pick 1st, 2nd ...upto 5th color.

1
  • How easily / often do you need to update the colors you want to cycle through? Given that it looks like getting a swatch color is tough, if not impossible, I made this script as a sort of a test.. Also if you didn't know already, you can set a shortcut key to launch a script.
    – Joonas
    Commented Oct 20, 2015 at 12:50

1 Answer 1

1

You should be able to do this in script. Tom Krcha has a script which you may be able to adapt (Add A Color To Swatches Panel In Photoshop Using ExtendScript/JSX):

var red = 255;
var green = 0;
var blue = 0;
var name = "Red";

var addColorDescriptor = new ActionDescriptor();
// Get reference to Swatches panel
var swatchesPanelReference = new ActionReference();
swatchesPanelReference.putClass(stringIDToTypeID('colors'));
addColorDescriptor.putReference(stringIDToTypeID('null'), swatchesPanelReference);
// Setup a swatch and give it a name
var descriptorSwatch = new ActionDescriptor();
descriptorSwatch.putString( stringIDToTypeID('name'), name);
// Add RGB color information to the swatch
var descriptorColor = new ActionDescriptor();
descriptorColor.putDouble(stringIDToTypeID('red'), red);
descriptorColor.putDouble(stringIDToTypeID('grain'), green); // grain = green
descriptorColor.putDouble(stringIDToTypeID('blue'), blue);
// Add RGB to the swatch
descriptorSwatch.putObject( stringIDToTypeID('color'), stringIDToTypeID('RGBColor'), descriptorColor);
// Add swatch to the color descriptor
addColorDescriptor.putObject( stringIDToTypeID('using'), stringIDToTypeID('colors'), descriptorSwatch);
// Send to Photoshop
executeAction( stringIDToTypeID('make'), addColorDescriptor, DialogModes.NO);

ref: http://tomkrcha.com/?p=3890

9
  • Thank you very much ! How can I pick color from swatch using script ?
    – S.M.
    Commented Oct 20, 2015 at 7:20
  • @S.M. The script: "Add a color to swatches panel in Photoshop". I'm pretty sure KJP meant this script as a starting point. It's not a straight up solution, as it does the opposite of what you want. Although, I have to ask. Let's say you have 10 swatches. how did you plan to choose what swatch to use?
    – Joonas
    Commented Oct 20, 2015 at 7:34
  • @ Joonas. Thanks for your reply. What I am really trying to achieve is, pick colors as foreground sequentially. Lets say I have 10 colors in swatches. I am trying to pick 1st, 2nd, 3rd... upto 10th. Is there a way ?
    – S.M.
    Commented Oct 20, 2015 at 7:38
  • @S.M. You mean like: press a hotkey once: Swatch #1 gets selected as the foreground color, press a hotkey for the second time: Swatch #2 gets selected as the foreground color... etc?
    – Joonas
    Commented Oct 20, 2015 at 7:40
  • @ Joonas Yes . Like a loop. It will choose swatch#1 do an operation, and choose swatch#2.. and continue until it have picked all colors in the swatches.
    – S.M.
    Commented Oct 20, 2015 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.