Adobe 65009333 Scripting Guide - Page 10

Walking through the script, Scripting terminology and the InCopy object model, Scripting terminology

Page 10 highlights

Getting Started Scripting terminology and the InCopy object model 10 Walking through the script This section presents a step-by-step analysis of what the script above does. 1. Establish communication with the InCopy application object: Refer to the application as app. 2. Create a new document and a reference to the document: Var myDocument = app.documents.add(); 3. Get a reference to the first story in the document (a standalone document always contains a story): var myStory = myDocument.stories.item(0); 4. Add text to the story by setting the contents property to a string. myStory.contents = "Hello World!"; Scripting terminology and the InCopy object model Now that you created your first InCopy script, it is time to learn more about the terminology of scripting languages in general and InCopy scripting in particular. Scripting terminology First, let's review a few common scripting terms and concepts. Comments Comments give you a way to 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 someone else). In this document, we use comments in the tutorial scripts. To include a comment in JavaScript, type // to the left of the comment, or surround the comment with /* and */. For example: // this is a comment /* and so is this */ Values The point size of a text character, the contents of a note, and the filename of a document are examples of values used in InCopy scripting. Values are the data your scripts use to do their work. The type of a value defines what sort of data the value contains. For example, the value type of the contents of a word is a text string; the value type of the leading of a paragraph is a number. Usually, the values used in scripts are numbers or text. The following table explains the value types most commonly used in InCopy scripting:

  • 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
Scripting terminology and the InCopy object model
10
Walking through the script
This section presents a step-by-step analysis of what the script above does.
1.
Establish communication with the InCopy application object:
Refer to the application as
app
.
2.
Create a new document and a reference to the document:
Var myDocument = app.documents.add();
3.
Get a reference to the first story in the document (a standalone document always contains a story):
var myStory = myDocument.stories.item(0);
4.
Add text to the story by setting the contents property to a string.
myStory.contents = "Hello World!";
Scripting terminology and the InCopy object model
Now that you created your first InCopy script, it is time to learn more about the terminology of scripting
languages in general and InCopy scripting in particular.
Scripting terminology
First, let’s review a few common scripting terms and concepts.
Comments
Comments give you a way to 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 someone else). In this
document, we use comments in the tutorial scripts.
To include a comment in JavaScript, type
//
to the left of the comment, or surround the comment with
/*
and
*/
. For example:
// this is a comment
/* and so is this */
Values
The point size of a text character, the contents of a note, and the filename of a document are examples of
values
used in InCopy scripting. Values are the data your scripts use to do their work.
The
type
of a value defines what sort of data the value contains. For example, the value type of the
contents of a word is a text string; the value type of the leading of a paragraph is a number. Usually, the
values used in scripts are numbers or text. The following table explains the value types most commonly
used in InCopy scripting: