1.6. Multiple AppleScript Commands

So far, your programs have done only a single thing: either perform a multiplication or display a dialog. It's obvious that you can do a lot more in your programs. Each line can contain another AppleScript command, which is executed sequentially, in turn, when the program is run.

The following Try It Out shows you how to add a sound effect to your program.

1.6.1.

1.6.1.1. Try It Out: Add a "Beep"

Suppose you're running a program and you detect that an error has occurred. For example, suppose the program can't locate a file it wants to use called myFavorites. It would be reasonable to put up a dialog box telling the user that the error occurred. Adding a beep can help get the user's attention.

Follow these steps to add a sound effect with AppleScript's beep command:

  1. Create a new AppleScript program with the following code:

    beep
    display dialog "Couldn't find myFavorites" buttons { "OK" } default button "OK"
    with icon stop
  2. Run the program. A beep will sound, and then a dialog is displayed with a stop icon and a single default button labeled OK. This is depicted in Figure 1-17.

    Figure 1.17. Figure 1-17

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.