Adobe 23102480 Scripting Guide - Page 52

Comparing Colors, Getting a Web Safe Color, Adobe Photoshop CS3 AppleScript Scripting Reference

Page 52 highlights

Adobe Photoshop CS3 Scripting Guide Photoshop CS3 Scripting Photoshop CS3 52 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 CS3 AppleScript Scripting Reference or in the Photoshop CS3 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 Look up the following in the Adobe Photoshop CS3 Visual Basic Scripting Reference, or in the Visual Basic Object Browser: ● model and cmyk as properties of the SolidColor object JS This example uses the foregroundColor property of the Application object to get the original color to be converted. The cmyk property of the SolidColor object that foregroundColor refers to provides a way to access the cmyk equivalent of the rgb color. var someColor = foregroundColor.cmyk Look up the following in the Adobe Photoshop CS3 JavaScript Scripting Reference, or in the ExtendScript Object Model Viewer: ● cmyk as a property of the SolidColor object ● foregroundColor as a property of the Application object Comparing Colors Using the equal colors (IsEqual/isEqual) command, you can compare colors. The following statements return true if the foreground color is visually equal to background color. ● AS: if equal colors foreground color with background color then ● VBS: If (appRef.ForegroundColor.IsEqual(appRef.BackgroundColor)) Then ● JS: if (app.foregroundColor.isEqual(backgroundColor)) Getting a Web Safe Color To convert a color to a web safe color use the web safe color command on AppleScript and the NearestWebColor/nearestWebColor property of the SolidColor object for VBScript and JavaScript.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85

Photoshop CS3
Adobe Photoshop CS3
Scripting Guide
Scripting Photoshop CS3
52
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 CS3 AppleScript Scripting Reference
or in the Photoshop CS3
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
Look up the following in the
Adobe Photoshop CS3 Visual Basic Scripting Reference
, or in the Visual Basic
Object Browser:
model
and
cmyk
as properties of the
SolidColor
object
JS
This example uses the
foregroundColor
property of the
Application
object to get the original color to
be converted. The
cmyk
property of the
SolidColor
object that
foregroundColor
refers to provides a
way to access the cmyk equivalent of the rgb color.
var someColor = foregroundColor.cmyk
Look up the following in the
Adobe Photoshop CS3 JavaScript Scripting Reference
, or in the ExtendScript
Object Model Viewer:
cmyk
as a property of the
SolidColor
object
foregroundColor
as a property of the
Application
object
Comparing Colors
Using the
equal colors (IsEqual/isEqual)
command, you can compare colors. The following
statements return
true
if the foreground color is visually equal to background color.
AS:
if equal colors foreground color with background color then
VBS:
If (appRef.ForegroundColor.IsEqual(appRef.BackgroundColor)) Then
JS:
if (app.foregroundColor.isEqual(backgroundColor))
Getting a Web Safe Color
To convert a color to a web safe color use the
web safe color
command on AppleScript and the
NearestWebColor/nearestWebColor
property of the
SolidColor
object for VBScript and JavaScript.