Using Scripts


Accessing scripts is easy ‚ they show up in the Scripts pane (Window Scripting Scripts) if you've placed scripts in the Scripts folder inside the folder that contains the InDesign CS application, as shown in Figure 37-1. Scripts don't have to be in the Scripts folder ‚ they can be anywhere on your computer ‚ but to use a script outside this folder means you have to double-click the script from your desktop rather than access it in InDesign.


Figure 37-1: The Scripts pane in InDesign.
New Feature ‚  

If you create many scripts, you can control how their names sort in the scripts list. Also, you can now assign keyboard shortcuts to scripts.

No matter what scripting language you use, there are several basic principles to observe. These fall into four basic categories:

  • Grammar. All languages ‚ including programming languages such as Pascal and C++, as well as scripting languages ‚ include grammatical components that are used in standardized sequences. In English, we combine nouns, verbs, adjectives, adverbs, and so on to create sentences. Everybody knows the meaning of "The weather is especially nice today," because it uses common words in a sequence that makes sense. The sentence "Nice is the especially today weather," has the right components, but it's arranged in the wrong sequence, so the meaning is lost.

  • Statements and syntax rules. In JavaScript, AppleScript, and VBA, verbs, nouns, adjectives, and prepositions are combined to create statements; statements are combined to form scripts. Verbs are also called commands and methods ; nouns are called objects; and adjectives are called properties. Syntax rules specify how statements and scripts must be constructed so that they can be understood by a computer.

  • The object hierarchy. All three scripting languages use a structural element called an object hierarchy. It's a fancy term for a simple concept. An object hierarchy works like a set of boxes within boxes. A large box contains a smaller box, which contains a smaller box, which contains a smaller box, and so on, until you reach the smallest box, which contains nothing and is the final level in the hierarchy of boxes.

  • The InDesign hierarchy. InDesign contains its own hierarchy, which lends itself nicely to scripting. A project contains layouts, a layout contains pages, pages contain boxes, and boxes contain text and pictures. You can create scripts that perform actions at any of these levels. In other words, with scripts you can create documents, add pages, add items to pages, and modify the contents of boxes ‚ right down to a particular character in a text box. You can think of this hierarchy in InDesign as a chain of command. You can't talk directly to an item that's at the bottom of the chain. Rather, you must first address the top level, then the next , and so on, until you've reached the item at the bottom of the chain. This is analogous to the way you use InDesign: You create new layouts, add pages, place text and graphics on the pages, and, finally, modify the contents of the frames containing those items.

    New Feature ‚  

    Scripts can now address individual graphics in a layout as objects, create dialog boxes, access object labels (which you can set in InDesign, as well as have InDesign automatically extract from converted QuarkXPress files), set object properties, and identify the file path on which the script resides.

If you're thinking about dabbling with any of the scripting languages supported by InDesign, the following words of both caution and encouragement are in order. First the encouragement: You don't necessarily need programming experience, scripting experience, or a pocket protector to begin creating scripts. A bit of curiosity and a touch of patience will suffice. Now the caution: Scripting is essentially a euphemism for programming (that is, figuring out the right commands and then typing them in for the application to execute). Writing scripts isn't a matter of choosing commands from menus , clicking and dragging, or entering values into fields; nor is it like writing a limerick. If you're starting from scratch, know in advance that you'll have to learn some new skills.

Learning to create scripts is like learning to swim: You can read books, documentation, and articles until your head spins , but eventually you have to get a little wet. The best way to learn about scripting is to write a script. So put on your swimsuit and dive in.

Be forewarned: There's something almost narcotic about creating scripts, and it's not uncommon for novice scriptwriters to get hooked. Don't be surprised if what starts out to be a 15-minute look-see turns into a multi- hour , late-night programming episode.

Note ‚  

Because scripting languages differ , you can't always duplicate the functionality of a specific script in one language into a script written in a different language.




Adobe InDesign CS Bible
Adobe InDesign CS3 Bible
ISBN: 0470119381
EAN: 2147483647
Year: 2003
Pages: 344
Authors: Galen Gruman

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