Scripting in the CS2 Applications


One of the most powerful, but least publicized, features of Adobe Creative Suite is its ability to be scripted. Scripting is a form of programming. Instead of using the interface of the applicationsthe buttons, palettes, and commands that we use every dayyou write out a series of commands to tell your CS2 application to perform a series of procedures. A script can be very simple, and only do one thing. Or it can be very complex and affect many things in the applicationor even in more than one application.

This book is not the place to learn to write scripts, but we'll give you an overview of scripting in the CS2 applications. If you'd like to write your own scripts, we'll tell where you can get more information.

Comparing Scripting with Actions and Batch Processing

Why bother writing a script? Can't actions and batch processing handle all your requests?

Not really. Actions and batch processing are limited to using features that are already in the user interface of your application. Scripting can make use of the underlying commands that drive the application, allowing you to extend the application. For example, unlike with an action, when scripting you can open, rename, or save a file. With AppleScript and Visual Basic you can also control other applications on your computer, and the operating systemall in one script.

Scripting can use conditional logic, allowing a variable to go in one direction with one result, and a different direction with a second result. (Example: In InDesign, if the frame is less than or equal to a certain size, color it red; if it is greater than that size, color it green.) A script can also work in loops: Keep doing a particular operation until you get a certain result, and then do something else.

Finally, scripts can contain variables. You can save the value of an output, and use it later in the same script.


Running a Script Is Easy

Before you immediately flip to another section, thinking "I'm no programmer," you should know that running a script is easy to do. All you need to learn is how to install and run it. And there are many useful scripts included with the Suite applications, and many more are easily available.

Scripting Languages

Photoshop, Illustrator, and InDesign support three widely used scripting languages:

  • AppleScript (Macintosh only) Apple installs tools on the Macintosh to create and run AppleScripts. An AppleScript can communicate between different Mac applications.

  • Visual Basic (Windows only) Microsoft provides similar platform-specific support as AppleScript. There are different "flavors" of Visual Basic tools available: See the references in the "Finding Scripts and Learning Scripting Section" to find out the details.

  • JavaScript is a scripting language that works on both platforms. Adobe uses a version of JavaScript called ExtendScript. For the first time, Adobe Creative Suite 2 installs a utility called the ExtendScript Toolkit, which includes an integrated environment for developing JavaScripts. (This is found on the Mac in Applications > Utilities > Adobe Utilities > ExtendScript Toolkit, and in Windows in Program Files > Adobe > Adobe Utilities > ExtendScript Toolkit.)

Acrobat 7 Professional, GoLive, and Bridge support JavaScript but don't support the other scripting languages.

Installing a Script

To install a script in Photoshop, Illustrator, or InDesign, put it in this location:

Mac: Applications > [Name of Application] > Presets > Scripts.

Windows: Program Files > Adobe > [Name of Application] > Presets > Scripts.

In Photoshop and Illustrator, some preinstalled scripts are found in the default location for the operating system.

InDesign's prebuilt scripts are not installed automatically, but are found on the CS2 Std Content installation CD in Technical Information > InDesign CS2 > Scripting > Adobe Sample Scripts. Drag either the AppleScript or JavaScript scripts (Mac) or the Visual Basic or JavaScript scripts (Windows) to the indicated location in the Scripts folder.

Running a Script

In Photoshop or Illustrator, to run a script, choose File > Scripts, and select a script from the submenu. Alternatively, in Photoshop choose File > Scripts > Browse, or in Illustrator choose File > Scripts > Other Scripts, and navigate to select the script you want to execute. Note that in Photoshop you can only run a JavaScript from the menu; to run an AppleScript or Visual Basic script, you must use an external editorlike Apple's Script Editor (installed automatically on Macs).

InDesign uses a Scripts palette to run scripts. Choose Window > Automation > Scripts to open it (Figure 15-22). Then either double-click the name of the script you want to execute, or choose Run Script from the palette menu.

Figure 15-22. Scripts palette in InDesign.


Tip: Use a Keyboard Shortcut in InDesign

If you really want to make it easy in InDesign, once you've installed your script, use Edit > Keyboard Shortcuts to assign a keystroke to run it. See "Editing Keyboard Shortcuts and Menus" in Chapter 7, "Managing and Customizing the Interface."


Adobe Bridge includes access to a few Workflow Automation Scripts. These are found in the Tools menu, and are described in the next section. To install a new JavaScript script, place it in the following folder:

Mac: Library > Application Support > Adobe > StartupScripts

Windows: Program Files > Common Files > Adobe > StartupScripts

For scripts in Acrobat, see the sidebar "Scripting in Acrobat." GoLive uses JavaScript Actions as we describe in the sidebar, "Different Kinds of Actions," above.

Trying Out the CS2 Scripts

Photoshop, Illustrator, and InDesign each include some scripts that are worth trying out. They'll whet your appetite for other scripts.

Photoshop Scripts

Five JavaScripts are installed by default in Photoshop, and found in the File > Scripts menu:

  • Image Processor is a heavy-duty script that allows you to scale, save in different formats, and apply actions to a large number of imagesall from one dialog box.

  • Export Layers To Files saves each layer in your file as a separate, flattened document, and allows you to choose the file format.

  • Layer Comps To PDF is Sandee's favorite. You can use this script to save layer comps and separate pages in a PDF presentation (Figure 15-23). (In "Layer Comps" in Chapter 12, "The Flexibility of Layers," we described how to create a set of layer comps in Photoshop.)

    Figure 15-23. Use the Layer Comps To PDF script to export Photoshop layer comps to separate pages in a PDF presentation.

  • Layer Comps To Files is like the preceding script, except that it saves each comp as a flattened file, with output options.

  • Layer Comps To WPG exports layer comps to a Web Photo Gallery, which we talk about in Chapter 17, "To the Web."

Illustrator Scripts

Most of the Illustrator scripts included with the application seem to be of most use if you're learning to write a script. But we found a couple that are worth checking out on the on CS2 Std Content installation CD, in Technical Information > Illustrator CS2 > Scripting > Sample Scripts > AppleScript (Mac) or Visual Basic (Windows). They somewhat compensate for Illustrator's lack of preflighting features. However, they don't work quite the way you expect, at least on the Macintosh. On the Mac, if you try to select the AppleScripts from the Script menu as we describe above, they are grayed out. Instead, you must double-click the script file to run them. The Visual Basic scripts (Windows) can be run from the menu.

  • Analyze Documents (Macintosh only) prompts you to find a folder that contains one or more Illustrator documents. It analyzes the files and gives you a list of fonts, gradients, spot colors, and placed images in all the documents. This could be useful when you're handing off your Illustrator files for output. (However, if the folder contains any files that Illustrator cannot open, the whole process fails ungracefully!)

  • Collect For Output collects the placed images in an Illustrator file. You need to create an Output folder first (the scripts prompts you for it); the script then makes a copy of your Illustrator file, including its placed images, and places it all into the folder. Initiate it by running the script when an Illustrator file is open, or by dragging the document file over the script file.

InDesign Scripts

InDesign comes with 21 scripts on the installation CDs, as we describe in the "Installing a Script" section above. Some of these add much-requested features to InDesign. Here are some examples:

  • AlignToPage aligns objects to specified positions on a page (Figure 15-24).

    Figure 15-24. The AlignToPage script aligns object to a pagea feature lacking in InDesign.

  • BreakFrame removes a selected text frame and its contents from a story, leaving the remainder of the story linked.

  • CropMarks draws crop and/or registration marks around objects that are selected.

  • MakeGrid creates a grid by subdividing or duplicating the objects that are selected.

  • SortParagraphs sorts the paragraphs of a text selection alphabetically.

Tip: Organize Your InDesign Scripts

If you gather many InDesign scripts, you can place them inside other folders within the Scripts folders for better organization.


Tip: Store Your Scripts Somewhere Else

If you need to reinstall InDesign, the scripts in your Script folder disappear. Place them somewhere else, and create aliases (Mac) or shortcuts (Windows) to them.


Scripting in Acrobat

In InDesign, Illustrator, and Photoshop, most of the application features are accessible to scripting. In Acrobat, the implementation of JavaScript is more limited: You can incorporate JavaScript code in page actions (performed when a page opens or closes); in document-level scripts; in bookmark and link actions; in form fields; and in batch sequences, which we describe in the "Batch Processing in the CS2 Applications" section above.


Bridge Scripts

There are three Workflow Automation Scripts included with Bridge. By this we mean that you can use Bridge to select files, and then run a JavaScript script, which calls one of the other CS2 applications to perform one of the following commands in the script:

  • Create InDesign Contact Sheet (on the Tools > InDesign menu) creates a contact sheet using InDesign for images you select in Bridge. As we describe in "Contact Sheets and Layer Comps," in Chapter 2, "Which Application Does What?", we prefer this script to Photoshop's Contact Sheet II, also available from Bridge. Instead of losing resolution, the images are simply scaled down within InDesign to their final size. By choosing an InDesign template, you can customize the appearance of the contact sheet.

  • Export To Flash (on the Tools > Illustrator menu) exports a selected file to Flash (SWF) format when you select an Adobe Illustrator (.ai) file in Bridge. This export command currently works only with Illustrator files.

  • Live Trace (on the Tools > Illustrator menu) lets you select images in Bridge, and then prompts you to choose which Live Trace preset you want to use and where you'd like to save the result. (We describe Illustrator's Live Trace tool for vectorizing images in Chapter 5, "Getting to the Point of Vector Graphics.")

Adobe Studio Exchange has scripts available that enhance Bridge (see the next section).

Finding Scripts and Learning Scripting

For those of you are who are not so technically inclined, your best bet is to be on the lookout for existing scripts that can ease your workload. Here are some good places to look:

  • Adobe Studio Exchange (http://share.studio.adobe.com/default.asp) has scripts available for Photoshop, Illustrator, InDesign, and Bridge. For example, the browsebar.jsx script adds a Browse Bar to Bridge so you can type in a path name, and the ImportCamera_BR.jsx script enhances importing images from a camera (or other removable media) to your hard drive. See theAppendix, "Creative Suite Resources," for more about this fabulous resource.

  • Adobe User to User Forums (http://www.adobe.com/support/forums/main.html) has several forums devoted to scripting, including sections for Acrobat, Bridge, Illustrator, InDesign, and Photoshop. It's often a source of scripts that are available free of charge (see the Appendix, "Creative Suite Resources").

Tip: Hire Someone to Write a Script

When you need a more complex script for your workflow, consider hiring a scripter to write one for you. In the long run, it can save you a bundle of money. For starting place, look for a scripter in the Adobe scripting forums.


We encourage you to try scripting, if you have the inclination. Here are some good sources of information when you're learning scripting:

  • Look at the CS2 Documentation. For each of the "big three" CS2 products (Photoshop, Illustrator, and InDesign), there are scripting guides found on the installation CDs. There is also a Bridge JavaScript reference. We give the locations for these in "The Extras" in Chapter 1, "Introducing Adobe Creative Suite." Unfortunately, there is no JavaScript guide for Acrobat, but you can download the Adobe JavaScript Scripting Guide and Adobe JavaScript Scripting Reference from the Adobe partners and developers web site at http://partners.adobe.com/asn/acrobat/index.jsp (click on the JavaScript support link on the left).

  • Look at the Sample Scripts. One of the best ways to learn scripting is to look at scripts that others have written. Start with the sample scripts found on the installation CDs.

  • Adobe User to User Forums. We'll refer you here again, because this is where all the hard-core scripters for JavaScript, AppleScript, and Visual Basic hang out.

  • Real World InDesign CS2. Because Ole Kvern, one of the co-authors of this book from Peachpit Press, is one of Adobe's scripting gurus, the Scripting chapter is a good source of down-to-earth information.

Here are a few more for those learning AppleScript:

  • For serious AppleScripters, LateNight Software's Script Debugger is highly recommended (http://www.latenightsw.com).

  • Shane Stanley and Ray Robertson's periodic AppleScript Pro Seminars are really valuable, and in recent years have included a full day devoted to InDesign (http://www.scriptingmatters.com/aspro.php).

  • Another good source of scripts and scripting help for AppleScript users is http://macscripter.net.



Real World(c) Adobe Creative Suite 2
Real World Adobe Creative Suite 2
ISBN: 0321334124
EAN: 2147483647
Year: N/A
Pages: 192

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net