Introduction to AppleScript

The following online materials are exerpted from the Apple Training Series book AppleScript 1-2-3.

What is AppleScript?
AppleScript is a language used to automate the actions of the Macintosh Operating System and many of its applications.
Whether a task is as simple as copying a file or as complex as building a real estate catalog, AppleScript can perform the requisite actions for you with “intelligence,” controlling applications and making decisions based on its observations or from information provided by its interaction with the person running the script.
Every day, businesses and individuals alike use AppleScript to create newspapers and books, manage networks, build DVDs, process images, generate web pages, backup files and folders, make videos, and much more. AppleScript is the most powerful, easy-to-use, automation tool available on any platform. And best of all, this technology is free and is built into every copy of the Mac OS!

The Script Editor

Since this tutorial is very “hands-on,” we’ll be writing scripts right away. To write a script, you’ll use the Script Editor application installed in your system. You can find this application in the AppleScript folder located in the Applications folder on your computer’s main hard drive. Navigate to this folder now and double-click the Script Editor icon to launch the application.


Our First Script
You’ll begin the process of learning AppleScript by writing a series a simple script commands in the form of a “tell statements.” A tell statement is a single line script beginning with the verb: tell. This verb is used to direct script actions at a specific application or scriptable object. A tell statement is composed of two parts:

A reference to the object to be scripted, and
The action to be performed.
Using this grammatical format or syntax, we can write scripts instructing the Finder to perform whatever actions we desire. Here's our first script:

A simple script statement to close all open Finder windows.

tell application "Finder" to close every window

Enter this script in the top pane of the Script Editor script window exactly as show (be sure to encase the word “Finder” in straight quotes). Click the Compile button on the script window to confirm that it has been written correctly and to prepare the script for use.

Next, click the Run button to play your script. The operating system will read the script and send the appropriate commands to the Finder application, which will then follow the instruction to close any open windows.

Congratulations, you’ve written and run your first AppleScript script!

ffmpeg osx