C
HAPTER
3: Scripting Photoshop
Working with color objects
52
Solid color classes
The solid color classes available in Photoshop are illustrated below.
Using hex values for RGB color
You can express RGB colors as hex (or
hexadecimal
) values. A hex value contains three pairs of numbers
which represent red, blue and green (in that order).
In AppleScript, the hex value is represented by the
hex
value
string property in class
RGB
hex
color
, and
you use the
convert
color
command described below to retrieve the hex value.
In VBScript and JavaScript, the
RGBColor
object has a string property called
HexValue/hexValue
.
Getting and converting colors
The following examples convert an RGB color to its CMYK equivalent.
AS
The following script, which assumes an RGB color model, gets the foreground color and then uses the
convert
command of the
color
class to convert the color to its CMYK equivalent.
get foreground color
convert color foreground color to CMYK
Look up the following in the
Adobe Photoshop CS4 AppleScript Scripting Reference
or in the Photoshop
AppleScript Dictionary:
➤
In the “Objects” section, the
foreground color
property of the class
application
➤
In the “Commands” section,
convert
VBS
The following script uses an
If
Then
statement and the
model
property of the
SolidColor
object to
determine the color model in use. The
If
Then
statement returns a
SolidColor
object; if it returns an
RGB
object, the
cmyk
property of the
SolidColor
object then allows you to access the color with its CMYK
equivalent.
Dim someColor
If (someColor.model = 2) Then
someColor.cmyk
'someColor.model = 2 indicates psColorModel --> 2 (psRGBModel)
End If
RGB
Color
CMYK
Color
Gray
Color
HSB
Color
Lab
Color
No
Color
Solid
Color
Color Classes