Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

In Mac OS and Mac OS X, what is AppleScript, and how do I use it?

AppleScript is an object-oriented scripting language with a syntax resembling ordinary English. You can use it to automate repetitive tasks in applications, the Finder, and other parts of Mac OS and Mac OS X.

Here is a simple example of an AppleScript, which tells the Finder to empty the Trash:

Tell application "Finder" activate empty trash end tell

Creating AppleScripts

If you are interested in writing your own AppleScript, the primary tool you will use is the Script Editor, which is part of a standard installation of Mac OS and Mac OS X. Scriptable applications contain an AppleScript dictionary which lists available commands. To view a dictionary in Script Editor, from the File menu, choose Open Dictionary... . Then select the application in the Open dialog box. Even if an application is not extensively scriptable, it should contain the standard set of commands which tell it to launch, quit, make a new document, and save a document.

The simplest way to create a new script is to use the Record feature of the Script Editor, but this will work only if an application is both scriptable and recordable. To record a script, do the following:

  1. In the Script Editor, click the Record button.

  2. Perform the actions you want to record.

  3. Click the Stop button.

When you have finished recording, you can click the Run button to reproduce the actions that are recordable through AppleScript.

Note: Not all commands in an AppleScript dictionary may be recordable.

Scripts can also be typed directly into the Script Editor. For help with AppleScript syntax, consult either the built-in Script Editor Help option, available from the Help menu, or Apple's AppleScript Language Guide.

Saving AppleScripts

Once an AppleScript is recorded or written, you can save it in the following ways:

  • Text: This saves the script in text form, uncompiled.

  • Compiled script: If your script is written with the correct syntax, the Script Editor will compile the script after you click the Check Syntax button or if you try to execute the script. Saved this way, the AppleScript can be run, but only by the Script Editor.

  • Application (Applet): Saved as an applet, the script can be run as a stand-alone application. To avoid a dialog box that asks if you want to run or quit the script when it is launched, check the box that says Never Show Startup Screen when saving the script.

  • Script bundle and application bundle: A bundle is a folder designed to appear as a single file. Inside the folder bundle are the code and resources used to execute the script. Both bundle formats have the same save options as their non-bundle versions.

    Note: Scripts saved in bundle format will not run on systems prior to Mac OS X 10.3.

This is document aemz in domain all.
Last modified on August 31, 2009.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.