Adobe 0046100128056 Scripting Guide - Page 118

Events, Understanding the Event Scripting Model, About event properties and event propagation

Page 118 highlights

8 Events InDesign scripting can respond to common application and document events, such as opening a file, creating a new file, printing, and importing text and graphic files from disk. In InDesign scripting, the event object responds to an event that occurs in the application. Scripts can be attached to events using the eventListener scripting object. Scripts that use events are the same as other scripts-the only difference is that they run automatically when the corresponding event occurs, rather than being run by the user (from the Scripts palette). This chapter shows how to work with InDesign event scripting. The sample scripts in this chapter are presented in order of complexity, starting with very simple scripts and building toward more complex operations. We assume that you have already read Adobe InDesign CS5 Scripting Tutorial and know how to create, install, and run a script. For a discussion of events related to menus, see Chapter 9, "Menus." The InDesign event scripting model is similar to the Worldwide Web Consortium (W3C) recommendation for Document Object Model Events. For more information, see http://www.w3c.org. Understanding the Event Scripting Model The InDesign event scripting model consists of a series of objects that correspond to the events that occur as you work with the application. The first object is the event, which corresponds to one of a limited series of actions in the InDesign user interface (or corresponding actions triggered by scripts). To respond to an event, you register an eventListener with an object capable of receiving the event. When the specified event reaches the object, the eventListener executes the script function defined in its handler function (which can be either a script function or a reference to a script file on disk). You can view the available events using the Object Model Viewer in the ExtendScript Toolkit. In the ExtendScript Toolkit, select the Event class, then click Class in the Types list to display a list of available event types in the Properties and Methods list. About event properties and event propagation When an action-whether initiated by a user or by a script-triggers an event, the event can spread, or propagate, through the scripting objects capable of responding to the event. When an event reaches an object that has an eventListener registered for that event, the eventListener is triggered by the event. An event can be handled by more than one object as it propagates. There are two types of event propagation: X None - Only the eventListeners registered to the event target are triggered by the event. The beforeDisplay event is an example of an event that does not propagate. X Bubbling - The event starts propagation at its target and triggers any qualifying eventListeners registered to the target. The event then proceeds upward through the scripting object model, 118

  • 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
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209

118
8
Events
InDesign scripting can respond to common application and document events, such as opening a file,
creating a new file, printing, and importing text and graphic files from disk. In InDesign scripting, the
event
object responds to an event that occurs in the application. Scripts can be attached to events using
the
eventListener
scripting object. Scripts that use events are the same as other scripts—the only
difference is that they run automatically when the corresponding event occurs, rather than being run by
the user (from the Scripts palette).
This chapter shows how to work with InDesign event scripting. The sample scripts in this chapter are
presented in order of complexity, starting with very simple scripts and building toward more complex
operations.
We assume that you have already read
Adobe InDesign CS5 Scripting Tutorial
and know how to create,
install, and run a script.
For a discussion of events related to menus, see
Chapter 9, “Menus.”
The InDesign event scripting model is similar to the Worldwide Web Consortium (W3C) recommendation
for Document Object Model Events. For more information, see
.
Understanding the Event Scripting Model
The InDesign event scripting model consists of a series of objects that correspond to the events that occur
as you work with the application. The first object is the
event
, which corresponds to one of a limited series
of actions in the InDesign user interface (or corresponding actions triggered by scripts).
To respond to an event, you register an
eventListener
with an object capable of receiving the event.
When the specified event reaches the object, the
eventListener
executes the script function defined in
its handler function (which can be either a script function or a reference to a script file on disk).
You can view the available events using the Object Model Viewer in the ExtendScript Toolkit. In the
ExtendScript Toolkit, select the Event class, then click Class in the Types list to display a list of available
event types in the Properties and Methods list.
About event properties and event propagation
When an action—whether initiated by a user or by a script—triggers an event, the event can spread, or
propagate
, through the scripting objects capable of responding to the event. When an event reaches an
object that has an
eventListener
registered for that event, the
eventListener
is triggered by the event.
An event can be handled by more than one object as it propagates.
There are two types of event propagation:
X
None —
Only the
eventListeners
registered to the event target are triggered by the event. The
beforeDisplay
event is an example of an event that does not propagate.
X
Bubbling
— The event starts propagation at its
target
and triggers any qualifying
eventListeners
registered to the
target
. The event then proceeds upward through the scripting object model,