Adobe 23101764 Scripting Guide - Page 19

AppleScript Sample Code, Visual Basic Sample Code

Page 19 highlights

Scripting basics 2 Object Model AppleScript Sample Code This code contains AppleScript commands that instruct the Photoshop application to create a new document with width and height in inches and place an art layer within the document. The art layer is then changed to a text layer, whose contents are set to "Hello World!". tell application "Adobe Photoshop CS" set docRef to make new document with properties ¬ {width:4 as inches, height:2 as inches} set artLayerRef to make new art layer in docRef set kind of artLayerRef to text layer set contents of text object of artLayerRef to "Hello, World!" end tell Visual Basic Sample Code This code contains Visual Basic commands that instruct Photoshop to configure the width and height of a new document in inches and place an art layer within the document. The art layer is then changed to a text item, whose contents are set to "Hello World!". Initial unit settings are restored after the script is run. Dim appRef As New Photoshop.Application Dim originalRulerUnits As Photoshop.PsUnits originalRulerUnits = appRef.Preferences.RulerUnits appRef.Preferences.RulerUnits = psInches Dim docRef As Photoshop.Document Dim artLayerRef As Photoshop.ArtLayer Dim textItemRef As Photoshop.TextItem Set docRef = appRef.Documents.Add(4, 2, 72, "Hello, World!") Set artLayerRef = docRef.ArtLayers.Add artLayerRef.Kind = psTextLayer Set textItemRef = artLayerRef.TextItem textItemRef.Contents = "Hello, World!" appRef.Preferences.RulerUnits = originalRulerUnits Photoshop CS Scripting Guide 15

  • 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
15
Scripting basics
Object Model
2
AppleScript Sample Code
This code contains AppleScript commands that instruct the Photoshop application to create a
new document with width and height in inches and place an art layer within the document.
The art layer is then changed to a text layer, whose contents are set to "Hello World!".
tell application "Adobe Photoshop CS"
set docRef to make new document with properties ¬
{width:4 as inches, height:2 as inches}
set artLayerRef to make new art layer in docRef
set kind of artLayerRef to text layer
set contents of text object of artLayerRef to "Hello, World!"
end tell
Visual Basic Sample Code
This code contains Visual Basic commands that instruct Photoshop to con
gure the width and
height of a new document in inches and place an art layer within the document. The art layer is
then changed to a text item, whose contents are set to "Hello World!". Initial unit settings are
restored after the script is run.
Dim appRef As New Photoshop.Application
Dim originalRulerUnits As Photoshop.PsUnits
originalRulerUnits = appRef.Preferences.RulerUnits
appRef.Preferences.RulerUnits = psInches
Dim docRef As Photoshop.Document
Dim artLayerRef As Photoshop.ArtLayer
Dim textItemRef As Photoshop.TextItem
Set docRef = appRef.Documents.Add(4, 2, 72, "Hello, World!")
Set artLayerRef = docRef.ArtLayers.Add
artLayerRef.Kind = psTextLayer
Set textItemRef = artLayerRef.TextItem
textItemRef.Contents = "Hello, World!"
appRef.Preferences.RulerUnits = originalRulerUnits