Apple Developer Connection
Advanced Search
Member Login Log In | Not a Member? Contact ADC

Getting Started with AppleScript

Technology Overview

AppleScript is a scripting language that provides convenient control of applications and of many parts of the Mac OS. AppleScript uses an English-like syntax that is approachable to scripters with little programming experience. Scripts can combine operations from applications and from the Mac OS to automate simple tasks or complex workflows.

AppleScript uses a type of message called an Apple event for the underlying interprocess communication between scripts and applications. Most applications must be able to respond to Apple events because the Mac OS uses Apple events for certain basic actions, such as launching an application and providing a list of documents for it to open. A scriptable application, however, goes beyond the basics to make its data and operations available to AppleScript scripts. To do this, the application must provide a terminology for scripters to use and the underlying Apple event code to support it.

Scriptable applications are popular because users can write scripts to combine the capabilities of multiple applications. Making your application scriptable can also provide benefits in areas such as rapid development and automated testing. Both Carbon and Cocoa applications can be made scriptable, and the Cocoa framework contains built-in support that minimizes the amount of code you have to write.

AppleScript provides limited support for displaying user-interface items from scripts. However, AppleScript Studio allows you to create Mac OS X applications that use AppleScript scripts to control complex user interfaces. That makes AppleScript Studio a useful tool for system administrators or others who need to quickly automate a process while providing a full user interface. It can also be useful for rapid user-interface prototyping. You can write AppleScript Studio applications using just AppleScript, or using a combination of AppleScript and system programming languages, such as C, Objective-C, and Java. AppleScript Studio relies on the Xcode Tools, which ship with Mac OS X and are also available for download.

The Automator application, available starting with Mac OS X version 10.4, provides a graphical interface for combining individual actions to create an automated workflow. Each action performs a distinct operation, such as copying a file, cropping a photo, or sending an email message. Actions in a workflow are executed sequentially, with each action typically taking the output of the previous action as its input. Workflows can be run from Automator or saved as applications you can run independently. Automator includes actions that work with the Finder, Mail, iTunes, and other Apple applications, and you can write actions that make key features of your applications available in Automator. You can write actions using AppleScript or Objective-C and do your development in Xcode, using the new Action project templates.

Start Here

To get a quick introduction to the basics of AppleScript:

  • Read AppleScript Overview for a broad overview of AppleScript, Apple events, and related technologies, with links to other documentation.

  • From the Finder Help menu, choose Mac Help, which launches Help Viewer. Then choose Library > AppleScript Help, for introductory information on working with AppleScript scripts.

  • Visit the AppleScript website for information, news, and additional resources.

Choose a Learning Path

Whatever your goal with AppleScript, you’ll want to read about the AppleScript language and learn how to use it to write scripts. If you’re an application developer, you’ll need additional information to write scriptable applications and to write Automator actions so that users can take full advantage of your applications in their Automator workflows.

Writing AppleScript Scripts

  • Browse the AppleScript Help, as described above in Start Here, to learn about writing scripts and using the Script Editor application (which is located in /Applications/AppleScript).

  • Read AppleScript Language Guide to learn about the basic features of the language and to find many simple script examples.

  • Refer to the AppleScript website for the latest AppleScript features in Mac OS X.

  • See Essential Sub-Routines for a large library of AppleScript routines for working with numbers, lists, sorting, text, and more.

Making Your Application Scriptable

You can support scripting in your application whether you develop in procedural C, C++, or Objective-C.

  • If you want to design a scriptable application, read Technical Note TN2106, Scripting Interface Guidelines, for information on designing a scripting terminology for your application. To learn more about the model-view-controller design pattern, which is useful for scriptable applications, see Cocoa Design Patterns in Cocoa Fundamentals Guide. For design guidelines for a scriptable Cocoa application, see Designing for Scriptability in Cocoa Scripting Guide.

  • For both a conceptual and task-oriented introduction to Apple events, the underlying communication mechanism for AppleScript and scriptable applications, read Apple Events Programming Guide. This information is more important if you are developing Carbon rather than Cocoa applications, but Cocoa developers may still want to skim it.

  • If you are developing in Objective-C, see Cocoa Scripting Guide for detailed information on working with scripting in Cocoa applications. For examples of scriptable Cocoa applications, see the Xcode projects for the Sketch and TextEdit applications, in /Developer/Examples/AppKit (available after you install the Xcode Tools).

  • If you are developing in procedural C or C++, read Coding Your Object Model for Advanced Scriptability to learn more about how to implement the object model for your application. See MoreAppleEvents and MoreOSL for sample code that demonstrates key features of a scriptable application, and includes libraries of routines for working with Apple events. Read Apple Events Programming Guide to learn how you can more easily work with Apple event structures in your application.

Providing Automator Actions for Your Application

You can use Xcode, Interface Builder, and AppleScript Studio to develop Automator actions that support key features of your application.

  • To learn how to create Automator actions, read Automator Programming Guide, which provides both overview and detailed information on how to build AppleScript-based and Cocoa-based actions. For sample Xcode projects for building actions, see /Developer/Examples/Automator. For information about the classes, constants, and other API you use with Automator, read Automator Framework Reference.

Creating an AppleScript Studio Application

You can use AppleScript Studio to quickly create applications with complex user interfaces that adhere to the guidelines in Apple Human Interface Guidelines.

  • To learn how to write AppleScript Studio applications, read AppleScript Studio Programming Guide, which includes a number of tutorials. For a complete list of the terminology supplied by AppleScript Studio applications, with many examples of how to use it, read AppleScript Studio Terminology Reference. For sample code, see the applications in /Developer/Examples/AppleScript Studio (available after you install the Xcode Tools).

Next Steps

The AppleScript Reference Library includes the following high-level resource pages, which can be bookmarked for easy access:

  • Guides

    Conceptual and how-to information for AppleScript.

  • Reference

    Focused, detailed descriptions in reference format for AppleScript.

  • Release Notes

    Late-breaking news and highlights of new or changed features in the latest release.

  • Sample Code

    Provides additional examples for writing code that works with Apple events and scripting.

  • Technical Notes

    Late-breaking documents on timely technology issues.

  • Technical Q&As

    Programming tips, code snippets, & FAQs by Apple’s support engineers.

  • Mailing Lists

    AppleScript mail lists include applescript-implementors for issues related to scriptable applications, applescript-users for issues related to writing AppleScript scripts, and applescript-studio for issues related to AppleScript Studio.

    Automator mail lists include automator-dev for developers creating new Automator actions and automator-users for users developing workflows and solutions using Automator.



Last updated: 2006-05-23




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.