How to save CMYK color Swatch

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

m5willmax
Posts: 1
Joined: Wed Feb 14, 2018 9:30 am

How to save CMYK color Swatch

Post by m5willmax »

Hi, sorry for my English. How can I save cmyk color to swatches in Photoshop CC 2014? Document color mode is CMYK. I found this code, but it saves RGB color. Changing 'RGBColor' to 'CMYKColor' or 'CMYK' and changing 'red', 'green', 'blue' to 'cyan', 'magenta', 'yellow', 'black' don't help. Photoshop creates a swatch, but it's broken.

Code: Select all


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);