Introduction to AppleScript Language Guide

This document is a guide to the AppleScript language—its lexical conventions, syntax, keywords, and other elements. It is intended primarily for use with AppleScript 2.0 or later and macOS version 10.5 or later.

AppleScript 2.0 can use scripts developed for any version of AppleScript from 1.1 through 1.10.7, any scripting addition created for AppleScript 1.5 or later for macOS, and any scriptable application for Mac OS v7.1 or later. A script created with AppleScript 2.0 can be used by any version of AppleScript back to version 1.1, provided it does not use features of AppleScript, scripting additions, or scriptable applications that are unavailable in that version.

What Is AppleScript?

AppleScript is a scripting language created by Apple. It allows users to directly control scriptable Macintosh applications, as well as parts of macOS itself. You can create scripts—sets of written instructions—to automate repetitive tasks, combine features from multiple scriptable applications, and create complex workflows.

A scriptable application is one that can be controlled by a script. For AppleScript, that means being responsive to interapplication messages, called Apple events, sent when a script command targets the application. (Apple events can also be sent directly from other applications and macOS.)

AppleScript itself provides a very small number of commands, but it provides a framework into which you can plug many task-specific commands—those provided by scriptable applications and scriptable parts of macOS.

Most script samples and script fragments in this guide use scriptable features of the Finder application, scriptable parts of macOS, or scriptable applications distributed with macOS, such as TextEdit (located in /Applications).

Who Should Read This Document?

You should use this document if you write or modify AppleScript scripts, or if you create scriptable applications and need to know how scripts should work.

AppleScript Language Guide assumes you are familiar with the high-level information about AppleScript found in AppleScript Overview.

Organization of This Document

This guide describes the AppleScript language in a series of chapters and appendixes.

The first five chapters introduce components of the language and basic concepts for using it, then provide additional overview on working with script objects and handler routines:

The following chapters provide reference for the AppleScript Language:

The following chapter describes an AppleScript-related feature of macOS:

The following appendixes provide additional information about the AppleScript language and how to work with errors in scripts:

Conventions Used in This Guide

Glossary terms are shown in boldface where they are defined.

The following conventions are used in syntax descriptions:

language element

Plain computer font indicates an element that you type exactly as shown. If there are special symbols (for example, + or &), you also type them exactly as shown.

placeholder

Italic text indicates a placeholder that you replace with an appropriate value.

[optional]

Brackets indicate that the enclosed language element or elements are optional.

(a group)

Parentheses group elements together.

However, the parentheses shown in Handler Syntax (Positional Parameters) are part of the syntax.

[optional]...

Three ellipsis points (...) after a group defined by brackets indicate that you can repeat the group of elements within brackets 0 or more times.

a | b | c

Vertical bars separate elements in a group from which you must choose a single element. The elements are often grouped within parentheses or brackets.

Filenames shown in scripts

Most filenames shown in examples in this document include extensions, such as rtf for a TextEdit document. Use of extensions in scripts is generally dependent on the “Show all file extensions” setting in the Advanced pane of Finder Preferences.

To work with the examples on your computer, you may need to modify either that setting or the filenames.

See Also

These Apple documents provide additional information for working with AppleScript:

For additional information on working with the AppleScript language and creating scripts, see one of the comprehensive third-party documents available in bookstores and online.