Adobe 27510753 Scripting Guide - Page 38

Adding the user interface

Page 38 highlights

30 Getting Started with InDesign Scripting Adobe InDesign CS2 Scripting Guide Like any other InDesign scripting object, each part of a dialog box has its own properties. A checkbox control, for example, has a property for its text ("static label") and another property for its state ("checked state"). The dropdown control has a property for setting the list of options that appears on the control's menu ("string list"). To use a dialog box in your script, you create the dialog box object, populate it with various controls, display the dialog box, and then gather values from the dialog box controls to use in your script. Dialog boxes remain in InDesign's memory until they are destroyed. This means that you can keep a dialog box in memory and have data stored in its properties used by multiple scripts, but it also means that the dialog boxes take up memory and should be disposed of when they are not in use. In general, you should destroy the dialog box object before your script finishes execution. Adding the user interface In this example, we'll add a simple user interface to our Hello World script. The options in the dialog box will provide a way for you to specify the example text (we assume that you're tired of the phrase "Hello World" by now) and change the point size of the text. These examples also use a handler (AppleScript), or function (VBScript, JavaScript), to get the live area of the current page ("myGetBounds"). AppleScript 1. Enter the following AppleScript in your script editor. --Simple User Interface Example tell application "Adobe InDesign CS2" activate set myDocument to make document set myDialog to make dialog tell myDialog set name to "Simple User Interface Example Script" set myDialogColumn to make dialog column tell myDialogColumn --Create a text entry field. set myTextEditField to make text editbox with properties ¬ {edit contents:"Hello World!", min width:180} --Create a number (real) entry field. set myPointSizeField to make real editbox with properties {edit contents:"72"} end tell show --Get the settings from the dialog box. --Get the point size from the point size field. set myPointSize to edit contents of myPointSizeField as real --Get the example text from the text edit field. set myString to edit contents of myTextEditField --Remove the dialog box from memory. destroy myDialog end tell tell page 1 of myDocument --Create a text frame. set myTextFrame to make text frame set geometric bounds of myTextFrame to my myGetBounds(myDocument, page 1 of myDocument) --Apply the settings from the dialog box to the text frame. set contents of myTextFrame to myString --Set the point size of the text in the text frame. set point size of text 1 of myTextFrame to myPointSize end tell end tell on myGetBounds(myDocument, myPage) tell application "Adobe InDesign CS2" set myPageHeight to page height of document preferences of myDocument

  • 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
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184

30
Getting Started with InDesign Scripting
Adobe InDesign CS2 Scripting Guide
Like any other InDesign scripting object, each part of a dialog box has its own properties. A checkbox control,
for example, has a property for its text (“static label”) and another property for its state (“checked state”). The
dropdown control has a property for setting the list of options that appears on the control’s menu (“string
list”).
To use a dialog box in your script, you create the dialog box object, populate it with various controls, display
the dialog box, and then gather values from the dialog box controls to use in your script. Dialog boxes remain
in InDesign’s memory until they are destroyed. This means that you can keep a dialog box in memory and
have data stored in its properties used by multiple scripts, but it also means that the dialog boxes take up
memory and should be disposed of when they are not in use. In general, you should destroy the dialog box
object before your script finishes execution.
Adding the user interface
In this example, we’ll add a simple user interface to our Hello World script. The options in the dialog box will
provide a way for you to specify the example text (we assume that you’re tired of the phrase “Hello World”
by now) and change the point size of the text. These examples also use a handler (AppleScript), or function
(VBScript, JavaScript), to get the
live area
of the current page (“myGetBounds”).
AppleScript
1.
Enter the following AppleScript in your script editor.
--Simple User Interface Example
tell application "Adobe InDesign CS2"
activate
set myDocument to make document
set myDialog to make dialog
tell myDialog
set name to "Simple User Interface Example Script"
set myDialogColumn to make dialog column
tell myDialogColumn
--Create a text entry field.
set myTextEditField to make text editbox with properties ¬
{edit contents:"Hello World!", min width:180}
--Create a number (real) entry field.
set myPointSizeField to make real editbox with properties {edit contents:"72"}
end tell
show
--Get the settings from the dialog box.
--Get the point size from the point size field.
set myPointSize to edit contents of myPointSizeField as real
--Get the example text from the text edit field.
set myString to edit contents of myTextEditField
--Remove the dialog box from memory.
destroy myDialog
end tell
tell page 1 of myDocument
--Create a text frame.
set myTextFrame to make text frame
set geometric bounds of myTextFrame to my myGetBounds(myDocument, page 1 of myDocument)
--Apply the settings from the dialog box to the text frame.
set contents of myTextFrame to myString
--Set the point size of the text in the text frame.
set point size of text 1 of myTextFrame to myPointSize
end tell
end tell
on myGetBounds(myDocument, myPage)
tell application "Adobe InDesign CS2"
set myPageHeight to page height of document preferences of myDocument