AppleScript Tutorial Introduction


    An introduction to this series of AppleScript tutorials, with background, purpose, scope, requirements, and explanation of the tools used.

Tutorial Home Page


Go back to the tutorial home page to see the complete contents.

Tutorial 1


After reading this introduction, proceed to tutorial 1.


These tutorials teach AppleScripting from the ground up. No previous experience is assumed, other than familiarity with Mac concepts such as menus, documents, windows, drawing, and spreadsheet cells.

This is the kind of tutorial and reference that I wish I had when I was learning AppleScript. I was frustrated that, although AppleScript was so "English like", my English attempts usually failed, without explanation. This tutorial focuses on knowing the syntax of the language, especially using the dictionary, aiming to take out the guesswork.

In its completion, this series is intended to be the most in depth and thorough tutorial available, and it may already have more text than any other on-line. About once a fortnight I hope to add a new tutorial (about 30 kB of text, plus pictures).

Each tutorial chapter builds on the previous tutorial, so I strongly suggest tackling them in sequence.

I welcome your feedback.

What is AppleScript?
AppleScript is a scripting language that you can use to control many programs on your Macintosh, as well as the system itself. You can write one script that tells the Finder to move some files, a database program to search for some data, a charting program to plot it and a web browser to pull in related data off the Internet. You can use this powerful inter-application communication to automate your every day tasks or stretch your software beyond its boxed limits.

Why is AppleScript Better than Macros?
At first, you might think that AppleScript is just a fancy macro language, like the macro feature built into AppleWorks to record mouse clicks and menu operations. But scripts are far more powerful than macros. Unlike macros, a script can:
    1. Read current information, such as how many cells are selected in a spreadsheet, and act accordingly.
    2. Make decisions or repeat the same action a number of times.
    3. When required, ask the user for input.
    4. Be edited. After you write a script, you can go back and change it without starting from scratch.
    5. Be moved easily from one computer to the next.
    6. Still work when a program is upgraded with few or no changes.
    7. Control other computers on the network.
    8. Integrate several applications towards one goal without the need to code in different languages.
    9. Be extended by adding scripting additions or upgraded software.
    10. Be triggered by a specified time interval or action (such as clicking on a button, selecting an item from a menu, or changing a spreadsheet cell or database record).

In order to follow the exercises in these tutorial lessons you will, of course, need to have AppleScript installed. As long as you have System 7.5 or later (Mac OS X preferred) installed on your Mac, AppleScript should already be on your computer as part of the standard install. This includes various system files, as well as the “Script Editor” application, in which we’ll do most of our work. This tutorial uses Mac OS X 10.3, but notes the first example of differences in previous systems in this different font style.

What Will We Script?
Fundamentally, you use AppleScript to control applications. It is almost useless by itself. So, in order to practice scripting, we need to script (control) a particular application or two. I chose AppleWorks for the following reasons. (Don’t worry if some terms here don’t make sense to you yet.)
    1. AppleWorks demonstrates scripting models fundamentally similar to a range of other programs, such as XPress (eg text frames and styles), Illustrator (eg graphic objects), FileMaker (eg records, fields), Excel (eg cells, charts), so it's a natural starting point.
    2. It has a rich AppleScript model, containing diverse objects such as word processing and database documents, cells, ovals, arcs, paragraphs, styles.
    3. AppleWorks objects and scripting results are more tangible than, say, the Finder. Watching a script draw a face, reformat some text or find a record, for example, is far more enlightening than seeing the Finder move some files.
    4. Apple increased its use of AppleWorks in its own AppleScript documentation, such as the “AppleScript Language Guide”, which changed in early 1999 from no references to AppleWorks to over 90, second only to the Finder.
    5. AppleWorks can trigger a script in a variety of ways including from the button bar, Scripts menu, custom formula, database change, check box or pop up menu.
    6. AppleWorks and AppleScript both run natively in Mac OS X, but also run on earlier systems.
    7. AppleWorks needs the help of scripts to provide features such as to: generate an word processing index, draw a prism, format text as title caps or small caps, unwrap text pasted from an email message, replace the value of a field in all records, use a median function, build a table of contents, draw text along an arc, and so on. The possibilities are virtually endless.

This series focusses on scripting AppleWorks. So you need AppleWorks 6.2.9 or later (recommended), preferably running on Mac OS X (10.3 or later preferred).

Earlier versions such as AppleWorks 5 or Mac OS 9 (even back as far as 7.5) should also work in most cases, and I try to give tips along the way of any differences you might encounter, in this different font style.

AppleWorks ships with all new consumer Macintosh computers, such as the iMac and iBook as well as previous models such as the Performa series.

Enhancement Pack
The first two tutorials use prewritten scripts from the Enhancement Pack for AppleWorks. This is a package of already written scripts so you can see what scripts do before getting your hands dirty writing your own. The remaining tutorials do not require the Enhancement Pack. If you don;t want to download the Enhancement Pack, at least read through the first two tutorials, and start actually doing the exercises when you get to Tutorial 3 (which does not require the Enhancement Pack).

Now, let’s get started with Tutorial 1, where you will learn how to install scripts and use them from within an application.

© 1998 - 2004 BareFeetWare
Please email us any queries about this page.