Hello World!

Let’s write a very simple script, save it, and run it. Do as follows (the method we’re about to describe is the quickest and easiest right now, if not the most elegant—we’ll sort that out shortly).

  • In InDesign, open the scripts panel (Window → Utilities → Scripts; in CS3/4: Window → Automation → Scripts), click on the “User” folder to display the scripts there, then right-click on any script’s name, and choose “Edit Script” from the flyout (see Figure 1).

  • InDesign’s script editor, the ExtendScript Toolkit (ESTK), is launched and the script you selected is opened in it. The screenshot in Figure 2 shows the ESTK.

  • Never mind what you see displayed: press Opt/Ctrl+A to select all text and press Del to delete it.

  • In the edit window, type the following line (see Figure 2):

    alert ("Hello World!");

    Figure 1. 

  • Choose File → Save As to save the script file under a different name, say, hello_world.jsx (you can use any name, but you must use the extension .jsx).

    Figure 2. 

    Figure 3. 

  • The script’s name will appear in InDesign’s Scripts panel. To run the script, double-click its name. You should see an alert on your screen with the message “Hello World!” see Figure 3.

In the next section we turn ...

Get Scripting InDesign CS3/4 with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.