Adobe 23101764 Scripting Guide - Page 62

AppleScript unit considerations

Page 62 highlights

Scripting Photoshop 3 Working with units appropriate for your script. After executing a script the original values of the rule settings should be restored if changed in the script. See section 3.6.3, "Changing ruler and type units" on page 61 for directions on setting unit values. AppleScript unit considerations AppleScript provides an additional way of working with unit values. You can provide values with an explicit unit type where unit values are used. When a typed value is provided its type overrides the ruler's current setting. For example, to create a document which is 4 inches wide by 5 inches high you would write: make new document with properties {width:inches 4, ¬ height:inches 5} The values returned for a Photoshop property which used units will be returned as a value of the current ruler type. Getting the height of the document created above: set docHeight to height of current document would return a value of 5.0, which represents 5 inches based on the current ruler settings. In AppleScript, you can optionally ask for a property value as a particular type. set docHeight to height of current document as points This would return a value of 360 (5 inches x 72 points per inch). IMPORTANT: Because Photoshop is a pixel-oriented application you may not always get back the same value as you pass in when setting a value. For example, if Ruler Units is set to mm units, and you create a document that is 30 x 30, the value returned for the height or width will be 30.056 if your document resolution is set to 72 ppi. The scripting interface assumes settings are measured by ppi. The length unit value types available AppleScript use are listed below: TABLE 3.1 AppleScript Length Unit Values inches feet yards miles points traditional points ciceros millimeters centimeters meters kilometers picas traditional picas Photoshop CS Scripting Guide 58

  • 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
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
58
Scripting Photoshop
Working with units
3
appropriate for your script. After executing a script the original values of the rule settings
should be restored if changed in the script. See section
3.6.3, “Changing ruler and type units”
on page 61
for directions on setting unit values.
AppleScript unit considerations
AppleScript provides an additional way of working with unit values. You can provide values
with an explicit unit type where unit values are used. When a typed value is provided its type
overrides the ruler’s current setting.
For example, to create a document which is 4 inches wide by 5 inches high you would write:
make new document with properties {width:inches 4, ¬
height:inches 5}
The values returned for a Photoshop property which used units will be returned as a value of
the current ruler type. Getting the height of the document created above:
set docHeight to height of current document
would return a value of 5.0, which represents 5 inches based on the current ruler settings.
In AppleScript, you can optionally ask for a property value as a particular type.
set docHeight to height of current document as points
This would return a value of 360 (5 inches x 72 points per inch).
IMPORTANT:
Because Photoshop is a pixel-oriented application you may not always get
back the same value as you pass in when setting a value. For example, if Ruler
Units is set to mm units, and you create a document that is 30 x 30, the value
returned for the height or width will be 30.056 if your document resolution is
set to 72 ppi. The scripting interface assumes settings are measured by ppi.
The length unit value types available AppleScript use are listed below:
T
ABLE
3.1
AppleScript Length Unit Values
inches
millimeters
feet
centimeters
yards
meters
miles
kilometers
points
picas
traditional points
traditional picas
ciceros