background image

     1

Adobe

®

 Illustrator

®

 CS

2

 Scripting 

GettingStarted with JavaScript

®

Introduction

Scripting offers an easy way to manipulate Illustrator files programmatically. You can write scripts to create 
documents and objects, and to perform many of the operations that you access interactively in Illustrator, 
using the palettes and windows. Scripts are particularly useful as a way to automate day-to-day tasks that 
are complex and repetitive. You simply write the script once, and then run it any time you need to 
accomplish that task. This saves you both time and the effort of remembering steps and sequences of 
operations. 

Illustrator CS

2

 supports JavaScript, an easy-to-use, platform-independent scripting language. A JavaScript 

program, or script, takes the form of a text file with the 

.js

 extension. You can use any text editor to write 

your scripts, such as TextEdit, Textpad, or BBEdit. 

This overview will help you to become familiar with  Illustrator scripting using JavaScript, by walking you 
through some example scripts  that manipulate objects in Illustrator CS

2

This document assumes that:

You are familiar with the Illustrator user interface, as described in the 

Illustrator CS

2

 User Guide. 

You are familiar with JavaScript programming language.

You have installed Illustrator CS

2

 version 1

2

.0 and an editor to create scripts, such as Textpad or TextEdit. 

Executing JavaScript Scripts

To run any script from Illustrator CS

2

:

1. Choose 

File>Scripts>Browse

.

2. Navigate to your script file.

3. Double-click the file or click 

Open

 to run the script. 

To make a script available as a menu item under Illustrator’s 

File>Scripts

 menu, place the script file in the 

directory 

Adobe Illustrator CS

2

\Presets\Scripts

, then restart Illustrator. Each time you launch 

Illustrator, every script found in this location is added as a menu item ,Your script will be listed among the 
prebuilt Automation Scripts that are available in this directory.

Accessing and Referencing Objects 

When you write a script, you must first decide what file, or 

document

, the script should act on. The script 

can create a new document, open an existing document, or act on a document that is already open. 

The script can create new objects in the document, operate on objects that the user has selected, or 
operate on objects that it finds in one of the 

object

 

collections

. The following examples illustrate various 

techniques for accessing, referencing, and manipulating Illustrator objects.

Reviews: