|
When you display a dialog with AppleScript you don't have to just use the standard Cancel and OK buttons, you can change the text to something more meaningful to your specific prompt. For instance, suppose you want to ask someone their age range:
display dialog "How old are you?" buttons {"Less than 1", "Older than 1"}
(Okay, not the greatest example in the world, but that's all I've got today.)
That results in a dialog that looks like this:
Specifying a default button
Note that this dialog doesn't have a button selected by default. A cool addition to this is that you can specify the default button when the dialog is displayed, like this:
display dialog "How old are you?" buttons {"Less than 1", "Older than 1"} default button 2
That example highlights the "Older than 1" button when the dialog is displayed.
Getting the result back
Of course it's not too useful to prompt someone like this unless you can also tell which button they clicked. You get the result back like this:
-- the following command should all be on one line, but I
-- wrapped it here readability
set answer to the button returned of
(display dialog "How old are you?"
buttons {"Less than 1", "Older than 1"} default button 2)
-- display the answer
display dialog "You selected " & answer
Add icons to your dialogs
You can also add an icon to your AppleScript dialog using the with icon syntax. Here are a few simple examples. First, the note icon:
display dialog "Hello" with icon note
Next, the stop icon:
display dialog "Hello" with icon stop
Finally, the caution icon:
display dialog "Hello" with icon caution
|