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 10. Handling User Input

IN THIS CHAPTER

  • What is user input?

  • Sending a message to the user

  • Asking for text input

  • Working with buttons

  • Choosing folders and files

  • Choosing from a list

  • Choosing an application

So far, you've learned about variables, operators, expressions, and loops, and so you should be feeling pretty comfortable with AppleScript. In this chapter, you're going to learn about handling user input.

User input comes in many different forms, and this chapter will cover the most common types of input you'll encounter as you create AppleScripts.

What Is User Input?

User input involves any situation in which you ask the user for input: filling in a text field, pushing a button, choosing a folder or set of files, choosing a color, or making some other choice. Sometimes, you end up simply communicating with the user in a one-way fashion — showing a dialog with an alert or using the system beep. Although these aren't technically examples of user input, I'm going to cover them here.

Despite the example of one-way communication, user input almost always involves two parts:

  • asking for the user input in some way; and

  • capturing the user's response.

What you do with that response is entirely up to you, of course; however, you almost always have to match the kind of user input device to your stated goal. If you want the user to choose a folder, then use the folder prompt, not a text input field. If you want to capture a text string from the user, then don't present them with an option to choose ...

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