Adobe 27510753 Scripting Guide - Page 84

Basic document management, Creating a new document, Opening a document

Page 84 highlights

76 Working with Documents in AppleScript Adobe InDesign CS2 Scripting Guide Basic document management In almost all situations, your script needs to either open or create a document, save it, and then close it. Creating a new document If a document does not already exist, you must create one. To create a document: --MakeDocument.as --An InDesign CS2 AppleScript --Creates a new document. tell application "Adobe InDesign CS2" set myDocument to make document end tell You can specify a document preset when you create a document: --MakeDocumentWithPreset.as --An InDesign CS2 AppleScript --Creates a new document using the specified document preset. --Replace "myDocumentPreset" in the following line with the name --of the document preset you want to use. tell application "Adobe InDesign CS2" set myDocument to make document with properties ¬ {document preset:"myDocumentPreset"} end tell As you create a document, you can open the document in hidden mode rather than displaying it in a window: --MakeDocumentWithParameters.as --MakeDocumentWithParameters.as --An InDesign CS2 AppleScript --Creates a new document without showing the document window. --The "showing window" parameter controls the visibility of the document. --Hidden doucments are not minimized, and will remain invisible until --you tell the document to create a new window. tell application "Adobe InDesign CS2" set myDocument to make document with properties {showing window:false} --To show the window: --tell myDocument --set myWindow to make window --end tell end tell Opening a document The following example script shows how to open an existing document. You can choose to prevent the document from displaying (hide it) by setting the showing window parameter of the open command to false (the default is true). You might want to do this to improve performance of a script. To show a hidden document, create a new window, as shown in the following script: --OpenFile.as --An InDesign CS2 AppleScript --Opens the specified file. tell application "Adobe InDesign CS2" --You can use the "showing window" parameter to open files --without displaying them. This can speed up many scripting --operations, and makes it possible for a script to operate --on a file in the background. To display a document you've --opened this way, tell the document to create a new window. --You'll have to fill in your own file path. set myDocument to open "yukino:myTestDocument.indd" without showing window

  • 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

76
Working with Documents in AppleScript
Adobe InDesign CS2 Scripting Guide
Basic document management
In almost all situations, your script needs to either open or create a document, save it, and then close it.
Creating a new document
If a document does not already exist, you must create one. To create a document:
--MakeDocument.as
--An InDesign CS2 AppleScript
--Creates a new document.
tell application "Adobe InDesign CS2"
set myDocument to make document
end tell
You can specify a document preset when you create a document:
--MakeDocumentWithPreset.as
--An InDesign CS2 AppleScript
--Creates a new document using the specified document preset.
--Replace "myDocumentPreset" in the following line with the name
--of the document preset you want to use.
tell application "Adobe InDesign CS2"
set myDocument to make document with properties
¬
{document preset:"myDocumentPreset"}
end tell
As you create a document, you can open the document in hidden mode rather than displaying it in a window:
--MakeDocumentWithParameters.as
--MakeDocumentWithParameters.as
--An InDesign CS2 AppleScript
--Creates a new document without showing the document window.
--The "showing window" parameter controls the visibility of the document.
--Hidden doucments are not minimized, and will remain invisible until
--you tell the document to create a new window.
tell application "Adobe InDesign CS2"
set myDocument to make document with properties {showing window:false}
--To show the window:
--tell myDocument
--set myWindow to make window
--end tell
end tell
Opening a document
The following example script shows how to open an existing document. You can choose to prevent the
document from displaying (hide it) by setting the
showing window
parameter of the
open
command to
false (the default is true). You might want to do this to improve performance of a script. To show a hidden
document, create a new window, as shown in the following script:
--OpenFile.as
--An InDesign CS2 AppleScript
--Opens the specified file.
tell application "Adobe InDesign CS2"
--You can use the "showing window" parameter to open files
--without displaying them. This can speed up many scripting
--operations, and makes it possible for a script to operate
--on a file in the background. To display a document you’ve
--opened this way, tell the document to create a new window.
--You’ll have to fill in your own file path.
set myDocument to open "yukino:myTestDocument.indd" without showing window