About This Book
Like most software these days, AppleScript doesn't come with a printed manual. To find your way around, you're expected to use Apple's Help Viewer program (in your Applications folder). But as you'll quickly discover, the help pages are tersely written, offer very little technical depth, lack useful examples, and provide no tutorials whatsoever.
The AppleScript Language Guide (http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf
is hardly any better. It hasn't been updated since the days of OS 8.5, and it reads more like an encyclopedia than a help file. Of course, it's wonderful to have a complete guide to the language for
, but it doesn't help much when you're learning the language.
The worst part of both documents, however, is that they're
help files: you can't mark your place, underline important passages, or read them in the bathroom (unless, of course, you take your laptop in there with you). And there's no more than a passing mention of powerful new features like multimedia support (Chapter 8), GUI Scripting (Chapter 12), or AppleScript Studio (Chapter 15). The purpose of this book, therefore, is to serve as the AppleScript manual that should have accompanied your computer.
What You'll Need
This book covers the AppleScript features found in Mac OS 10.3 ("Panther"). If you have an earlier operating system, visit www.apple.com/macosx/upgrade/ for information on how to upgrade.
Furthermore, you may want a copy of these other programs that are used with some of the scripts in this book:
Adobe Photoshop CS ($650)
. Photoshop is the staple of any graphic pro's software library, and its AppleScript support is nearly unbeatable. If you don't feel like spending your retirement savings on software, just use the free 30-day trial version from www.adobe.com/products/tryadobe/main.jsp#product=39.
FileMaker Pro 7 ($300)
. FileMaker is a powerful database program that can organize virtually
kind of information. You can download a 30-day trial version from
://www.filemaker.com/downloads/trial_download.html, and that'll work just as well.
Power Users' Clinic
If AppleScript just doesn't cut it for a certain task, you have plenty of other options. OS X comes with one of the most complete sets of languages around, and you can add even more languages by installing the Xcode Tools (Chapter 14). Here's a look at alternatives to AppleScript:
is famous for its power, flexibility, and totally alien-looking grammar. Many Web sites use Perl scripts for processing credit card payments, for exampleand it works on virtually every operating system available. If you need to throw together programs that you can run
, this might be your language. Check out
, Third Edition (O'Reilly) for details.
is known for its simplicity and clever design. Some people use it for whipping up quick
of future programs, while others use it for making scripts that run Web sites. You can find out more in a book like
, Second Edition (O'Reilly).
is a method of linking together various Unix commands (Chapter 13). Among Unix hackers, it's a popular method for automating computer
, much as AppleScript is for Mac fans. You can find
examples in a book like
Wicked Cool Shell Scripts
are used on numerous Web pages to control the look of these Web sites. Each language has specific uses (PHP is often used for managing online databases, for example) and disadvantages (ActionScript works only if the Flash plug-in is installed, for example). None of these languages,
, can easily work with AppleScript. You can find online tutorials for all three at www.theopensourcery.com/ostutor.htm.
are the languages that are used to create the vast majority of commercial software programs. Microsoft Word, Adobe Photoshop, TextEdit, Safari, and virtually ever other program you use daily were written using at least one of these three languages. These C-based languages are known for being fast, powerful, and hard to learnand you need the Xcode Tools to use them. Visit http://cprog.oreilly.com/ for more.
is intended to let you write a program on one operating system and have it run on all others. It's used a lot online (for programs like
and chat rooms), and it requires that you install the Xcode Tools to program in it. You can find out more in a book like
, Second Edition (O'Reilly).
Microsoft Word 2004 ($230)
. Word is the time-
, cross-platform standard for word processing documents. It's available as part of the Microsoft Office 2004 suite ($400), which also includes PowerPoint (for presentations), Excel (for spreadsheets), and Entourage (for emailing and creating calendars). You can download a free 30-day trial of the whole package from www.microsoft.com/mac/default.aspx?pid=office2004td.
Many of the scripts in this book will work with an earlier version of these programs, but the scripts may behave somewhat differently. It's a good idea, therefore, to download the free trial copies of the newest versions, so you can follow along easily with the scripts in this book.
About the Outline
This book is divided into four
, each containing several chapters:
Part 1, AppleScript Overview
covers the basics of using AppleScript to control your Mac. You'll learn how to crack
the scripts that Apple gives you for freeand how to change what they do. These three chapters also explain the purpose of the built-in Script Editor program, and show you how to make the most of your time there.
Part 2, Everyday Scripting Tasks
explains how to use AppleScript for automating typical jobs: renaming files, organizing your iPhoto library, playing music, and so on. These are also the chapters where you'll learn about AppleScript's different ways of storing information, such as lists,
, and database records.
Part 3, Power-User Features
takes you beyond the basics into truly time-saving territory. You'll learn how to make the Finder run scripts whenever you open a folder, and how to work around the scripting limitations in programs like System Preferences. These chapters also show you how to mix AppleScript with other powerful tools, to squeeze the most power possible from your scripts.
Part 4, Appendixes
offers three useful references. Appendix A lists the Mac OS X programs that play best with AppleScript, so you can figure out which programs to avoid and which ones to use. Appendix B shows you how to move HyperCard stacks into Mac OS X, using AppleScript to ease the transfer. Finally, Appendix C sends you off into the great universe of advanced AppleScript books and Web sites.
Along the way, you'll get a lot more out of this book if you have the free Missing CD, where you'll find all the scripts from this book prewritten for you. Using that, you won't have to retype all the long scripts by hand, and you'll save yourself both time and typos. Page Chapter 2 has instructions for downloading the Missing CD.
Throughout this book, and throughout the Missing Manual series, you'll find sentences like this one: "Open the System folder
Fonts folder." That's shorthand for a much longer instruction that directs you to open three nested folders in sequence, like this: "On your hard drive, you'll find a folder called System. Open it. Inside the System window is a folder called Libraries. Open that. Inside
folder is yet another one called Fonts. Double-click to open it, too."
Similarly, this kind of arrow shorthand helps to simplify the business of choosing commands in
, such as
Position on Left. That instruction is just another way of saying, "Click the Apple menu to open it, navigate to the Dock submenu, and then choose Position on Left."
At www.missingmanuals.com, you'll find news, articles, and updates to the books in this series. But if you click the
of this book and then click the Errata link, you'll find a unique resource: a list of corrections and updates that have been made in successive printings of this book. You can mark important corrections right in your own copy of the book, if you like.
In fact, the same page offers an
for you to submit such corrections and updates yourself. In an effort to keep the book as up-to-date and accurate as possible, each time we print more copies of the book, we'll make any confirmed corrections you've suggested. Thanks in advance for reporting any glitches you find!
In the meantime, we'd love to hear your suggestions for new books in the Missing Manual line. There's a place for that on the Web site, too, as well as a place to sign up for free email notification of new titles in the series.
When you see a Safari enabled icon on the cover of your favorite technology book, that means it's available online through the O'Reilly Network Safari Bookshelf. Safari offers a solution that's better than e-Books: it's a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it free at http://safari.oreilly.com.
The Very Basics
To use this book, and indeed to use a Macintosh computer, you need to know a few basics. This book assumes that you're familiar with these terms and concepts (if you're not, pick up a book like
Mac OS X: The Missing Manual
. This book gives you three kinds of instructions that require you to use the mouse that's attached to your Mac. To
means to point the arrow cursor at something on the screen and thenwithout moving the cursor at allto press and release the clicker button on the mouse (or laptop trackpad). To
, of course, means to click twice in rapid succession, again without moving the cursor at all. And to
means to move the cursor while keeping the button held down.
When you're told to
something, you click while pressing the
key (which is
to the Space bar). Such
work the same wayjust click while pressing the corresponding key at the bottom of your keyboard.
are the words in the lightly striped bar at the top of your screen. You can either click one of these words to open a pull-down menu of commands (and then click on a command) or click and hold the button as you drag down the menu to the desired command (and release the button to activate the command). Either method works just as well.
Apple has officially changed what it calls the little menu that pops up when you Control-click something on the screen. It's still a contextual menu, in that the menu choices depend on the context of what you clickbut now it's called a
. That term not only matches what it's called in Windows, but it's more descriptive. Shortcut menu is the
you'll find in this book.
If you've mastered this much information, you have all the technical background you need to enjoy
AppleScript: The Missing Manual