O'Reilly logo

Apple® Automator with AppleScript® Bible by Thomas Myer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required