
Photoshop 7.0 Scripting Guide
77
Scripting Photoshop
Color objects
3
3.14 Color objects
From scripting you can use the same range of colors that are available from the Photoshop user
interface. Each has its own set of properties, which are specific to the color. For example, the
RGB color class contains three properties — red, blue and green.
3.14.1 Setting a Color
Here’s how to set the foreground color to a CMYK color in AppleScript.
set foreground color to {class:CMYK color, cyan:20.0, ¬
magenta:90.0, yellow:50.0, black:50.0}
Because you can use any color model, you could also write the following to set the foreground
to an RGB color.
set foreground color to { class:RGB color, red:80.0, green:120.0,¬
blue:57.0 }
In Visual Basic and JavaScript, the
SolidColor
object handles all colors. To set the
foreground color you should create a
SolidColor
object, set its color model by assigning the
color model values and then set the foreground color to the solid color. Here’s how:
VB:
solidColor = CreateObject("Photoshop.SolidColor")
appRef.ForegroundColor = solidColor
JS:
var solidColor = new SolidColor();
foregroundColor = solidColor;
SolidColor class
Visual Basic and JavaScript have an additional class called the
SolidColor
class. This class
contains a property for each color model. To use this object, first create an instance of a
SolidColor
object, then set its appropriate color model properties. Once a color model has
been assigned to a
SolidColor
object, the
SolidColor
object cannot be reassigned to a
different color model. Below are examples on how to create a
SolidColor
object and set its
CMYK property.
VB:
Dim solidColor As Photoshop.SolidColor
Set solidColor = CreateObject("Photoshop.SolidColor")
solidColor. CMYK.Cyan = 20
solidColor.CMYK.Magenta = 90
solidColor.CMYK.Yellow = 50