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

1.5.1.

1.5.1.1. Try It Out: Using the display dialog's Buttons Parameter

Follow these steps to eliminate the Cancel button from the previous dialog box:

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

    buttons {"OK"}

    Your complete command line should look like this:

    display dialog "Programming in AppleScript is fun." buttons { "OK" }
  2. Compile and run the program. You see the dialog box shown in Figure 1-13.

    Figure 1.13. Figure 1-13

Because of the changes you made to the code, the dialog box no longer contains a Cancel button but just the single button labeled OK.

1.5.1.2. How It Works

The word buttons that you added to your program is an optional parameter to the display dialog command. AppleScript commands often accept parameters that enable you to extend the functionality of a command.

You can see that AppleScript, unlike any other programming language you probably have used, employs English words in its vocabulary. This allows you to write commands that are easy to read. However, it's also a trap that ...

Get Beginning AppleScript® 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.