Chapter 12. Applets and Droplets

IN THIS CHAPTER

  • What are applets?

  • Three applets

  • What are droplets?

  • Two droplets

In Chapter 11, you learned how to create reusable subroutines. Learning how to work with subroutines marks a serious step forward, as it allows you to code smarter and create reusable automation solutions.

In this chapter, you're going to take your knowledge one step further and learn how to create applets and droplets. As you'll see, applets and droplets are both very simple to comprehend, but open you up to a whole new world of possibilities in your scripting.

What Are Applets?

An applet is an application with a minimal user interface that nonetheless stands alone. It has its own icon and can be double-clicked to make its code run. It doesn't need to run inside of the Script Editor, which is what you've been doing so far in this book. The reason why it can run standalone is because an applet contains some compiled bootstrap code inside it that allows it to run in that fashion.

Just about any AppleScript you create can be turned into an applet. There's really no difference between a simple script that contains say "hello" and an applet with the same code, except that the applet can run by itself when you double-click its icon.

Creating an applet is extremely simple and requires only two rules (and even one of these rules is optional):

  1. First, you should encapsulate your code in an on run statement. This isn't necessary, as the run command is implied, but it's good practice.

  2. Second, ...

Get Apple® Automator with AppleScript® Bible 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.