Adobe 23101764 Scripting Guide - Page 66

Executing JavaScripts from AS or VB

Page 66 highlights

Scripting Photoshop 3 Executing JavaScripts from AS or VB In Visual Basic and JavaScript ruler units and type units are properties of the Preferences, accessed through the application object's preferences property as shown below. VB: appRef.Preferences.RulerUnits = PsInches appRef.Preferences.TypeUnits = PsTypePixels appRef.Preferences.PointSize = PsPostScriptPoints JS: app.preferences.rulerUnits = Units.INCHES; app.preferences.typeUnits = TypeUnits.PIXELS; app.preferences.pointSize = PointType.POSTSCRIPT; IMPORTANT: Remember to reset the unit settings back to the original values at the end of a script. 3.7 Executing JavaScripts from AS or VB You may want to take advantage of the platform-independence of JavaScript by running scripts from AppleScript or Visual Basic. For AppleScript, use do javascript. For Visual Basic, use either the Application's DoJavaScript or DoJavaScriptFile method. DoJavaScript takes a string, which is the JavaScript code to execute. DoJavaScriptFile opens a file that contains the JavaScript code as illustrated below: AS: set scriptFile to "myscript" as alias do javascript scriptFile VB: Dim appRef As Photoshop.Application Set appRef = CreateObject("Photoshop.Application") appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.js") Photoshop CS Scripting Guide 62

  • 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
62
Scripting Photoshop
Executing JavaScripts from AS or VB
3
In Visual Basic and JavaScript
ruler units
and
type units
are properties of the
Preferences
, accessed through the application object's preferences property as shown
below.
VB:
appRef.Preferences.RulerUnits = PsInches
appRef.Preferences.TypeUnits = PsTypePixels
appRef.Preferences.PointSize = PsPostScriptPoints
JS:
app.preferences.rulerUnits = Units.INCHES;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.preferences.pointSize = PointType.POSTSCRIPT;
IMPORTANT:
Remember to reset the unit settings back to the original values at the end of a
script.
3.7 Executing JavaScripts from AS or VB
You may want to take advantage of the platform-independence of JavaScript by running
scripts from AppleScript or Visual Basic.
For AppleScript, use
do javascript
.
For Visual Basic, use either the Application's
DoJavaScript
or
DoJavaScriptFile
method.
DoJavaScript
takes a string, which is the JavaScript code to execute.
DoJavaScriptFile
opens a
le that contains the JavaScript code as illustrated below:
AS:
set scriptFile to "myscript" as alias
do javascript scriptFile
VB:
Dim appRef As Photoshop.Application
Set appRef = CreateObject("Photoshop.Application")
appRef.DoJavaScriptFile ("D:\\Scripts\\MosaicTiles.js")