Copy link to clipboard
Copied
Is there a way to use scripts to set the CMYK value of a color swatch? Say I have a swatch named "Color 1," can I use scripts to set the CMYK (or RGB) values for that swatch?
app.activeDocument.colors.item("Primary").colorValue = [0,51,160];
Found this to be the correct answer. Where "Primary" is the swatch name and [0,51,160] are the RGB values
Copy link to clipboard
Copied
A color (swatch) has the following properties:
color value: RGB values in range 0-255, CMYK values from 0 to 100, or LAB L (values from 0 to 100), A (-128 to 127, and B(-128 to 127)
model: spot, process, registration, or mixedinkmodel
space (RGB, CMYK, LAB, or MixedInk
To create a swatch or change an existing swatch you can use the following with AppleScript:
set swatchName to "Blue"
tell application "Adobe InDesign CC 2019"
set docRef to document 1
tell docRef
if not (exists swatch swatchName) then
set myColor to make color with properties {name:swatchName, moodel:process, space:CMYK, color value:{100, 50, 0, 0}}
else
set myColor to swatch swatchName
set properties of myColor to {moodel:process, space:CMYK, color value:{100, 50, 0, 0}}
end if
--to check that color was created correctly
get properties of swatch swatchName
end tell
end tell
Note that in the example above the document is creating the swatch. If the application creates the swatch (without tell/end tell to docRef) the color will be effective for all documents created thereafter.
Copy link to clipboard
Copied
If you want to run the code on Windows environment you can try the following.
var color = app.documents[0].swatches.itemByName("Color1")
if(color.isValid)
{
if(color.space == ColorSpace.CMYK)
color.colorValue = [10,10,10,10] //Replace with the values you want
else if(color.space == ColorSpace.RGB)
color.colorValue = [23,12,23] //Replace with the values you want
}
-Manan
Copy link to clipboard
Copied
app.activeDocument.colors.item("Primary").colorValue = [0,51,160];
Found this to be the correct answer. Where "Primary" is the swatch name and [0,51,160] are the RGB values
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more