8.12. Summary

A handler provides a way of writing code that you can reuse for other applications. It also provides a way for you to divide your programming tasks into smaller, modularized pieces. In this chapter, you learned the following points about working with handlers:

  • Handlers can be written to take one or more parameters or arguments.

  • You can provide a simple, comma-separated list of parameters (known as positional parameters); or you can define your handlers to use labeled parameters, in which case the arguments can be specified in any order when the handler is called.

  • Arguments are passed to a handler by value. The handler cannot modify these arguments, unless a list, record, date, or script object is passed as the argument. The handler can change individual elements of a list or record, as well as properties of a date object.

  • You can declare local and global variables. How they are declared influences the scope of the variables in your program.

  • Handlers can be loaded into the program using the load script command.

You learn more about special handlers that are automatically called when certain events occur—such as running your program, quitting your program, or dragging a file on top of your program's icon—in Chapter 10, which deals with applications.

In the next chapter, you learn how to predict the types of program errors you may encounter and how to handle them. Before proceeding, however, try the exercises that follow to test your understanding of the material covered ...

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.