Exploring AppleScript


AppleScript is a scripting language developed by Apple and initially released with System 7.5 that can be used to control Macs, networks, and scriptable applications, including InDesign. The AppleScript language was designed to be as close to normal English as possible so that average Mac users ‚ specifically , those who aren't familiar with programming languages ‚ can understand and use it.

New Feature ‚  

InDesign can now run text-only AppleScripts in addition to compiled (binary) ones.

Learning the language

Many of the actions specified in AppleScripts read like sentences you might use in everyday conversation, such as:

 set color of myFrame to "Black" 

or

 set applied font of myCharacterStyle to "Times" 
Getting more information on AppleScript

Before you venture too far into scripting, you should review the AppleScript- related information provided with the Mac OS and with InDesign:

  • Mac scripting documentation and tools. Apple places the AppleScript documentation on its Web site at www.apple.com/applescript . In your hard drive's Applications folder, you should have a folder called AppleScript that contains the Script Editor program, along with a folder of example scripts and the AppleScript Script Menu that adds the Script menu to the Finder. Apple also offers a professional AppleScript editor called AppleScript Studio for download at its developer Web site, http://developers.apple.com/tools.macosxtools.html .

  • InDesign scripting documentation. The InDesign CD contains a 600-plus-page PDF file that explains scripting, including AppleScript programming, for InDesign. This document, although a bit on the technical side, is a valuable resource. It includes an overview of Apple events scripting and the object model, as well as a list of InDesign-specific scripting terms and scripting examples.

If you want still more information about AppleScript, several books are available, including AppleScript in a Nutshell: A Desktop Quick Reference , by Bruce W. Perry; Danny Goodman's AppleScript Handbook , 2nd Edition; and AppleScript 1-2-3 , by Sal Soghoian.

 

What you need to write and run scripts

The Script Editor, provided with the Mac OS, lets you write scripts. You'll find the Script Editor inside the AppleScript folder inside your Applications folder (at the root level of your hard drive). An uncompiled script is essentially a text file, so you can actually write scripts with any word processor. The Script Editor, however, was created for writing AppleScripts and includes several handy features for scriptwriters.

Checking for syntax errors

The next step is to determine if the statements are correctly constructed . Click the Check Syntax button. If the Script Editor encounters a syntax error, it alerts you and highlights the cause of the error. If the script's syntax is correct, all statements except the first and last are indented, and a number of words are displayed in bold, as illustrated in Figure 37-2. Your script has been compiled and is ready to test.


Figure 37-2: The Script Editor window containing sample AppleScript text. When you check the syntax of a script, the Script Editor applies formatting and indents.

Running your script

Click the Run button and then sit back and watch. If you've done everything correctly, you'll see InDesign become the active program, and then the actions you put in your script will take place. Voil ƒ   ‚ and congratulations! You can now call yourself a scripter without blushing. That's all there is to creating and running a script.

If you have trouble getting a script to run, double-check the name that InDesign uses for itself. It might use InDesign ‚ CS or simply InDesign ‚ (yes, the name may include the registered trademark symbol). If you run a script from AppleScript (rather than just double-clicking it) and AppleScript can't find InDesign, it will give you a dialog box with which you find the InDesign program. When you've found and selected the InDesign application, AppleScript will find out what InDesign's filename is and use that in your script.

Saving your script

When you're finished writing and testing a script, choose Save from the Script Editor's File menu. Name your script, choose its storage location, and choose Compiled Script from the Format pop-up menu. It's best to save the script in the Scripts folder inside the InDesign folder, so it will show up in the Scripts menu (after you restart InDesign).

Note ‚  

If you save the script in Application format and want to edit your script later, you must open it by dragging and dropping it on the Script Editor application. This is because Application-format scripts are designed to immediately run when double-clicked. You would choose the Application format when creating scripts for use by others, since chances are you don't want them to open the script in Script Editor but instead simply want them to use the script by double-clicking it like any other application.

Locating more AppleScript tools

A few software utilities are also available for AppleScripters. The most widely used is Script Debugger, from Late Night Software ($189, www.latenightsw.com ); it's an interface development tool to quickly create AppleScript-based applications that have the standard Mac look and feel. Apple also offers its AppleScript Studio as a free download to developers who register at the Apple site; this is more capable than the basic Script Editor that comes with Mac OS X.




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