Adobe 27510753 Scripting Guide - Page 15

Making script files readable, Commenting the script, Continuing long lines in AppleScript and VBScript

Page 15 highlights

Adobe InDesign CS2 Scripting Guide Scripting Basics 7 Making script files readable Comments within scripts and formatting of scripts make them easier to understand and to maintain. Commenting the script Comments let you add descriptive text to a script. The scripting system ignores comments as the script executes; this prevents comments from producing errors when you run your script. Comments are useful when you want to document the operation of a script (for yourself or for someone else). To include a comment in an AppleScript, type "--" to the left of your comment or surround the comment with "(*" and "*)". In VBScript, type "Rem" (for "remark") or "'" (a single straight quote) to the left of the comment. Type the comment marker at the beginning of a line to make the entire line a comment. In JavaScript, type "//" to the left of the comment, or surround the comment with "/*" and "*/". For example: AppleScript VBScript JavaScript --this is a comment (* and so is this *) Rem this is a comment ' and so is this // this is a comment /* and so is this */ Continuing long lines in AppleScript and VBScript In both AppleScript and VBScript, a carriage return at the end of a line signals the end of the statement. Script lines, however, can be quite long. How can you make the script more readable without breaking the long lines? Both AppleScript and VBScript define special continuation characters-characters that break a line but that direct the script to read the broken line as a legitimate instruction. In AppleScript, type Option+Return (displays as ¬) to enter a continuation character. In VBScript, type an underscore (_) followed by a carriage return at the end of the line to continue the line. In both languages, you cannot put the continuation character inside a string. Continuing long lines in JavaScript In JavaScript, a semicolon (;) indicates the end of a statement. Statements can contain carriage returns, so there's no need for a continuation character. At the same time, InDesign's ExtendScript interpreter does not require semicolons at the ends of statements, and interprets each line as a complete statement if it is possible to do so. For example: return true; is not interpreted as: return true; In general, therefore, it's best to end each line with a semicolon, and to insert returns only at the ends of statements.

  • 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

Adobe InDesign CS2 Scripting Guide
Scripting Basics
7
Making script files readable
Comments within scripts and formatting of scripts make them easier to understand and to maintain.
Commenting the script
Comments let you add descriptive text to a script. The scripting system ignores comments as the script
executes; this prevents comments from producing errors when you run your script. Comments are useful
when you want to document the operation of a script (for yourself or for someone else).
To include a comment in an AppleScript, type “--” to the left of your comment or surround the comment with
“(*” and “*)”. In VBScript, type “Rem” (for “remark”) or “'” (a single straight quote) to the left of the comment.
Type the comment marker at the beginning of a line to make the entire line a comment. In JavaScript, type “//”
to the left of the comment, or surround the comment with “/*” and “*/”. For example:
AppleScript
--this is a comment
(* and so is this *)
VBScript
Rem this is a comment
' and so is this
JavaScript
// this is a comment
/* and so is this */
Continuing long lines in AppleScript and VBScript
In both AppleScript and VBScript, a carriage return at the end of a line signals the end of the statement. Script
lines, however, can be quite long. How can you make the script more readable without breaking the long
lines?
Both AppleScript and VBScript define special
continuation
characters—characters that break a line but that
direct the script to read the broken line as a legitimate instruction. In AppleScript, type Option+Return
(displays as
¬) to enter a continuation character. In VBScript, type an underscore (_) followed by a carriage
return at the end of the line to continue the line.
In both languages, you cannot put the continuation character inside a string.
Continuing long lines in JavaScript
In JavaScript, a semicolon (;) indicates the end of a statement. Statements can contain carriage returns, so
there’s no need for a continuation character. At the same time, InDesign’s ExtendScript interpreter does not
require semicolons at the ends of statements, and interprets each line as a complete statement if it is possible
to do so. For example:
return
true;
is not interpreted as:
return true;
In general, therefore, it’s best to end each line with a semicolon, and to insert returns only at the ends of
statements.