By Mark L. Chambers

The easiest way to get started with AppleScript is to use some scripts that others have written already. Scripts are small files that contain a list of commands that tells your Mac what functions to perform and when.

Fortunately, Apple is kind enough to provide you with several completed scripts with your installation of Yosemite. You can find a large cache of scripts in the scripts folder, found in the Library folder, under Scripts.

Many scripts (but not all) end with the extension .scpt.

Before you get started running scripts, however, you should know a few things.

Identifying scripts in the field

Each script you encounter is in one of these three formats:

  • Script application: Some AppleScripts act much like an application. To use one, simply double-click it in Finder, and off it goes to perform whatever tasks it was meant to do. Depending on an internal setting of the script, it might quit when it’s finished doing its thing. Scripts are typically identified by the icon that you see in the figure.

    image0.jpg

  • Compiled script: You might also encounter AppleScripts that won’t run without the aid of another application. Apple calls these compiled scripts. Although they can’t execute on their own, they do have the capabilities of a script built in. They just require a host application to use them.

  • Text file: The third category of AppleScript you might encounter is a script stored in a text file. This kind of script also needs a host application before it can do anything. The main difference between a text file script and a compiled script is that you can read a text file script in any application that can open a text file.

The Script Editor application

Compiled scripts and text file scripts require some sort of host application before they can perform any action. Luckily, Yosemite provides you with just such a host: Script Editor, which comes with OS X and can execute any AppleScript with ease. With Script Editor, you can also do much more, including these things:

  • View or modify an AppleScript

  • Create an AppleScript

  • Check an AppleScript for errors

  • Save scripts in one of the three possible formats

To launch Script Editor, click the Launchpad icon (which bears a rocket icon) on the Dock, click the Utilities/Other folder, and then click the Script Editor icon. From the familiar Open dialog, click New Document; the Script Editor application displays an empty, script-editing window.

image1.jpg

Executing a script

With Script Editor running, you can run any AppleScript you can find. To get you started, Apple conveniently provides a handful of useful scripts. Navigate to the Scripts folder, which is located in the Library folder.

Scripts are divided into folders based on functionality, such as fonts, mail, and navigation. For example, open the Font Book folder, where you’ll find a script named Delete Empty Collections.scpt.

Double-click the script to open it. Because it’s a compiled script and not an application script, Script Editor automatically loads the script and comes to the foreground. This particular script opens the Font Book application and checks for empty font collections. If it finds any, the script displays a prompt asking for confirmation and deletes the empty collection if you click the OK button.

To see the script in action, click the Run button or press Command+R.

image2.jpg