Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

Chapter 1. Writing Your First AppleScrip... > Understanding the Buttons Parameter ... - Pg. 17

Writing Your First AppleScript Program So that you don't get confused, remember the Compile button compiles your program but does not run it. The Run button also compiles your program if it has changed since the last time it was compiled. Then, if no errors are detected, it runs your program. When you run your program, the dialog box shown in Figure 1-12 appears on your screen. Figure 1-12 As you can see, the phrase Programming in AppleScript is fun. is displayed in the dialog box, without the quotes you typed around those characters. Those double quotes are used to define the beginning and end of your character string. Whatever is contained inside those quotes gets displayed by the display dialog command. You are also shown two buttons, one labeled Cancel, and the other OK. The OK button is highlighted, indicating that the default action that will be taken if you press the Return key. Click the OK button (or press the Return key) to return control back to Script Editor. Notice that the following appears in the Result pane: {button returned:"OK"} You see that this window doesn't just display the results of performing arithmetic operations. This time the window tells you that the OK button was clicked. This may not seem important now, but later you learn how to test which button is clicked in your program and how to take appropriate action based on that test. As a quick note, if you click the Cancel button instead of OK, no result is displayed in the Result pane. That's because, unless you take special action, the program is immediately terminated when you cancel it. Understanding the Buttons Parameter in the display dialog Command In the example shown in the preceding section, the Cancel button served no purpose. You can get rid of the Cancel button by using a buttons parameter with the display dialog command. The following Try It Out shows you how. Try It Out 1. Using the display dialog's Buttons Parameter Follow these steps to eliminate the Cancel button from the previous dialog box: Go back to the program you saved in the preceding Try It Out and add the following characters to the end of the display dialog command. 17