Adobe 65009333 Scripting Guide - Page 9

Using the scripts in this document, Your first InCopy script - pdf

Page 9 highlights

Getting Started Using the scripts in this document 9 Using the scripts in this document To use any script from this document, either open the tutorial script file (the filename is given before each script). The files are stored in a zip archive, InCopyCS4ScriptingGuideScripts.zip. When you uncompress the archive, you can move the folder containing the scripts written in the scripting language you want to use (AppleScript, JavaScript, or VBScript) to your Scripts Panel folder. Working with the script files is much easier than entering the script yourself or copying and pasting from this document. If you do not have access to the script archive, you can enter the scripting code shown in this chapter. To do this: 1. Copy the script from this Adobe PDF document and paste it into the ExtendScript Toolkit. 2. Save the script as a plain-text file in the Scripts Panel folder (see "Installing scripts" on page 7), using the file extension .jsx. 3. Choose Windows > Scripts to display the Scripts panel. 4. Double-click the script name in the Scripts panel to run the script. Entering scripts manually will only work for the scripts shown in this chapter. The scripts shown in the other chapters are script fragments, not complete scripts. To run these scripts, you must use the scripts from the script archive. NOTE: If you are entering the examples yourself (rather than using the scripts from the script archive), it is very important you use the same capitalization as shown in the example. JavaScript is case-sensitive, and the scripts will fail if they do not use the capitalization shown. NOTE: If you are copying and pasting scripts from this document, be aware that line breaks caused by the layout of the document can cause errors in your script. As it can be very difficult to find such errors, we recommend hat you use the scripts in the zip archive. Your first InCopy script Next, we create an InCopy script that creates a new document, adds a text frame, then enters text in the text frame. While this seems trivial, it demonstrates how to do the following: ➤ Establish communication with InCopy. ➤ Create a new document. ➤ Add text to a story. Start the ExtendScript Toolkit (or a text editor) and enter the following script (or open the HelloWorld tutorial script): var myDocument = app.documents.add(); var myStory = myDocument.stories.item(0); myStory.contents = "Hello World!"; Save the script as a plain-text file with the file extension .jsx in the Scripts Panel folder (see "Installing scripts" on page 7). To run the script, double-click the script name in the Scripts panel (or select InCopy CS4 from the application target pop-up menu in the ExtendScript Toolkit, then click Run).

  • 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

Getting Started
Using the scripts in this document
9
Using the scripts in this document
To use any script from this document, either open the tutorial script file (the filename is given before each
script). The files are stored in a zip archive,
InCopyCS4ScriptingGuideScripts.zip
. When you
uncompress the archive, you can move the folder containing the scripts written in the scripting language
you want to use (AppleScript, JavaScript, or VBScript) to your Scripts Panel folder. Working with the script
files is much easier than entering the script yourself or copying and pasting from this document.
If you do not have access to the script archive, you can enter the scripting code shown in this chapter. To
do this:
1.
Copy the script from this Adobe PDF document and paste it into the ExtendScript Toolkit.
2.
Save the script as a plain-text file in the Scripts Panel folder (see
Installing scripts
” on page 7
), using
the file extension
.jsx
.
3.
Choose Windows > Scripts to display the Scripts panel.
4.
Double-click the script name in the Scripts panel to run the script.
Entering scripts manually will only work for the scripts shown in this chapter. The scripts shown in the
other chapters are script fragments, not complete scripts. To run these scripts, you must use the scripts
from the script archive.
NO
TE
:
If you are entering the examples yourself (rather than using the scripts from the script archive), it is
very important you use the same capitalization as shown in the example. JavaScript is case-sensitive, and
the scripts will fail if they do not use the capitalization shown.
N
OTE
:
If you are copying and pasting scripts from this document, be aware that line breaks caused by the
layout of the document can cause errors in your script. As it can be very difficult to find such errors, we
recommend hat you use the scripts in the zip archive.
Your first InCopy script
Next, we create an InCopy script that creates a new document, adds a text frame, then enters text in the
text frame. While this seems trivial, it demonstrates how to do the following:
Establish communication with InCopy.
Create a new document.
Add text to a story.
Start the ExtendScript Toolkit (or a text editor) and enter the following script (or open the HelloWorld
tutorial script):
var myDocument = app.documents.add();
var myStory = myDocument.stories.item(0);
myStory.contents = "Hello World!";
Save the script as a plain-text file with the file extension
.jsx
in the Scripts Panel folder (see
Installing
scripts
” on page 7
). To run the script, double-click the script name in the Scripts panel (or select InCopy
CS4 from the application target pop-up menu in the ExtendScript Toolkit, then click Run).