You are here:HomeiPodApple Software→AppleScript
AppleScript      
Written by yangying  
March 05, 2008 09:46

From Mac Guides

AppleScript is a scripting language developed by Apple Computer, which uses English-like syntax.

Description

Many people dismiss AppleScript as an inferior language due to its inability to do certain things, and due to its English-like syntax which programmers of other languages can find restricting. However they are often misinformed. While AppleScript is not designed for making full-fledged applications (although AppleScript Studio is bridging this gap), it specializes in communicating with and manipulating other, "scriptable" applications. For example, you could create a script to gather song information from iTunes and send it to a buddy in iChat. This script would be communicating with two different applications, something which is difficult if not impossible to do using other languages.

History

AppleScript was first introduced in October 1993 with the Mac OS 7.1.1 update, made possible by the addition of Apple Events to the operating system in Mac OS 7. QuarkXPress was one of the first applications to support it, and its AppleScript support is used as an explanation as to why the Mac remained popular in the publishing market even after Quark was ported to Windows.

Small but relatively frequent AppleScript updates have been made since its introduction, adding new language features. However, AppleScript support was sometimes difficult to add to applications, so many developers avoided doing so. A significant change came with the release of Mac OS X, when Cocoa developers could implement AppleScript support in a much simpler way than ever before, resulting in an increase in support for the language.

Editors

Most AppleScript developers edit their scripts with Script Editor (located at /Applications/AppleScript/Script Editor), which is developed by Apple and bundled with Mac OS X. There are also several third party editors.

If you have Apple's Developer Tools installed, you can use Xcode to create AppleScript applications. Using the Xcode suite, you can create custom interfaces to use for your AppleScript application. This requires a lot more background knowledge than Script Editor but is also more powerful.

For users who find the AppleScript language difficult, Automator is another alternative. Introduced in Mac OS X 10.4 (Tiger), it allows you to set up "workflows" without writing any code. Automator can be more limiting than AppleScript.

Dictionaries

For AppleScript to communicate with an application, the application must have an AppleScript dictionary. These dictionaries list all classes, properties and commands supported by the application. The dictionaries can be viewed from within Script Editor by choosing the "Open Dictionary..." command from the File menu, then choosing an application.

Language Examples

Hello World

The first example is a very simple one that displays a dialog displaying the traditional "Hello World" message. It demonstrates the English-like syntax that AppleScript uses.

display dialog "Hello World" buttons "OK" default button "OK" 

The above example uses the "display dialog" command" with several parameters. Other parameters, such as "with icon" and "default answer", also exist but are always optional.