Lesson 16. Subroutines

What Is a Subroutine?

How Does a Subroutine Work?

Why Use Subroutines?

An Example Using iTunes

Subroutine Miscellany

What’s Next?

Anytime a script you’re working on starts to get long and complicated, you should think about using subroutines. Subroutines are also sometimes referred to as subroutine handlers or, simply, handlers.

In this chapter, we’ll explain subroutines and demonstrate them using a single, long script. The script is fun to use if you have a lot of songs in your iTunes library. It asks you for a “theme”—a word or phrase that might be found in the titles of several of your songs, such as love or crazy—and creates a new playlist in iTunes gathering them together for easy listening. Alternatively, it creates ...

Get Apple Pro Training Series: AppleScript 1-2-3 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.