Scripting is the most powerful feature in Adobe® InDesign® CS3. No other feature can save you as much time, trouble, and money as scripting. Almost anything you can do with the user interface; you can do with a script. You can draw frames, enter and format text, place graphics, and print or export the pages of the document.
Any action that can change a document or its contents can be scripted. There even are a few things you can do in scripting that you cannot do using the user interface. Scripts can create menus, add menu items, create and display dialog boxes and panels, and respond to user-interface selections.
Scripts can read and write text files, parse XML data, and communicate with other applications. Scripts can do everything from very small tasks (like setting a tab stop at the location of the text cursor) to providing complete features (InDesign’s XHTML export feature is provided by a script). You can start with simple scripts that do only one thing and move on to scripts that automate your entire publishing workflow.
Most of the things scripting cannot do—like setting up a workspace or defining a set of keyboard shortcuts—are things that have to do with the user interface. In addition, scripts cannot add new types of objects to an InDesign document or add new, fundamental capabilities to the program, like a new text-composition engine.
For that type of extensibility, you must use the InDesign Software Development Kit (SDK), which shows you to write compiled plug-ins using C++. We tend to think of scripting in terms of long, repetitive tasks, like laying out a phone book. It also is good for things like the following:
- Automating the myriad, small, annoying tasks you face every day.
- Customizing InDesign to match your work habits and layouts.
- Achieving creative effects that would be difficult or impossible to attain by other means.
Installing an InDesign script is easy: put the script file in the Scripts Panel folder inside the Scripts folder in your InDesign application folder. (Create the Scripts folder if it does not already exist.) Alternately, put the script inside the Scripts Panel folder in your user-preferences folder. Your user-preferences folder is at
~\Documents and Settings\user_name\Application Data\Adobe \InDesign\Version 5.0\Scripts
where ~ is your system volume and user_name is your user name. Once the script is in the folder, it appears on the Scripts panel inside InDesign.
To display the panel, choose Window > Automation > Scripts. You also can put aliases/shortcuts to scripts (or to folders containing scripts) in the Scripts Panel folder, and they will appear in the Scripts panel. To run a specific script when InDesign starts, put the script inside a folder named “Startup Scripts” inside the Scripts folder (create this folder if it does not already exist).
To run a script, display the Scripts panel (choose Window > Automation > Scripts), then double-click the script name in the Scripts panel. Many scripts display user-interface items (like dialog boxes or panels) and display alerts if necessary.
The InDesign Scripts panel is the easiest and best way to run most InDesign scripts. If the panel is not already visible, you can display it by choosing Window > Automation > Scripts. Scripts run from the Scripts panel run faster than scripts run from the Finder (Mac OS®) or Explorer (Windows®). To view the script actions as they execute, choose Enable Redraw from the Scripts panel menu.
To open the folder containing a script shown in the Scripts panel, hold down the Command (Mac OS) or Ctrl-Shift (Windows) keys and double-click the script’s name. Alternately, choose Reveal in Finder (Mac OS) or Reveal in Explorer (Windows) from the Scripts panel menu. The folder containing the script opens in the Finder (Mac OS) or Explorer (Windows).
Scripts run as a series of actions, which means you can undo the changes the script made to a document by choosing Undo from the Edit menu. This can help you troubleshoot a script, as you can step backward through each change.
To add a keyboard shortcut for a script, choose Edit > Keyboard Shortcuts, select an editable shortcut set from the Set menu, then choose Product Area > Scripts. A list of the scripts in your Scripts panel appears. Select a script and assign a keyboard shortcut as you would for any other InDesign feature.
Other versions of Visual Basic include Visual Basic 5 Control Creation Edition (CCE), Visual Basic 6, Visual Basic .NET, and Visual Basic 2005 Express Edition. Versions of Visual Basic prior to Visual Basic .NET work well with InDesign scripting. Visual Basic .NET and newer versions work less well, because they lack the Variant data type, which is used extensively in InDesign scripting.
Many applications contain Visual Basic for Applications (VBA), like Microsoft Word, Microsoft Excel, Microsoft Visio, or AutoCAD. Although you can use VBA to create InDesign scripts, InDesign does not include VBA. To use VBScript or Visual Basic for InDesign scripting in Windows XP, you must install InDesign from a user account that has Administrator privileges.