Adobe InDesign CS4 Scripting Tutorial
Getting started
9
Your first InDesign script
Next, we will create an InDesign script that creates a new document, adds a text frame, and enters text in
the text frame. This demonstrates how to do the following:
➤
Establish communication with InDesign.
➤
Create a new document.
➤
Create a text frame on a specific page.
➤
Add text to a text frame.
AppleScript
Start the Script Editor application (you can find it in your Applications folder, inside the AppleScript folder).
Enter the following script (or open the
HelloWorld.applescript
tutorial script):
tell application "Adobe InDesign CS4"
set myDocument to make document
tell page 1 of myDocument
set myTextFrame to make text frame
set geometric bounds of myTextFrame to {"6p", "6p", "24p", "24p"}
set contents of myTextFrame to "Hello World!"
end tell
end tell
Save the script as text with the file extension
.applescript
to the Scripts Panel folder (see
“Installing
scripts” on page 6
). To run the script, double-click the script name in the Scripts panel or click the Run
button in the Script Editor window.
JavaScript
Start the ExtendScript Toolkit (or a text editor). Enter the following script (or open the
HelloWorld.jsx
tutorial script):
var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];
myTextFrame.contents = "Hello World!";
Save the script as a plain-text file with the
.jsx
file extension to the Scripts Panel folder (see
“Installing
scripts” on page 6
). To run the script, double-click the script name in the Scripts panel, or select InDesign
from the application target pop-up menu in the ExtendScript Toolkit and then click the Run button).
VBScript
Start a text editor (e.g., Notepad) and enter the following script (or open the
HelloWorld.vbs
tutorial
script):
Set myInDesign = CreateObject("InDesign.Application.CS4")
Set myDocument = myInDesign.Documents.Add
Set myTextFrame = myDocument.Pages.Item(1).TextFrames.Add
myTextFrame.GeometricBounds = Array("6p", "6p", "24p", "24p")
myTextFrame.Contents = "Hello World!"