Let user pick 1 of three actions using a dialogue box

Ok, I’ve got a guy who can’t remember what program to run to do certain tasks. So i want to create a script for him that asks him what he wants to do. All I’ve got so far is the basic steps for the code:

display dialogue “What would you like to do?”
Give the user 3 buttons to choose from
If button1 is clicked, tell application1 activate
If button2 is clicked, tell application2 activate
If button3 is clicked, tell application3 activate

Model: 2008 Macbook Pro 2.6 GHz
Browser: Internet Explorer 6.0
Operating System: Mac OS X (10.5)

Hi,

easiest solution:


display dialog "What would you like to do?" buttons {"iTunes", "iPhoto", "Mail"}
activate application (button returned of result)

Note: The names of the buttons must match the exact names of the applications

Wow, that is a lot simpler than what I was trying to make it. While playing with script after I posted, I found this would work (because he doesn’t remember the names of the programs and what they do):

display dialog "What is the task?" buttons ["Music", "Pictures", "Mail"]
if button returned of result is "Music" then
tell application "iTunes" to activate
  end tell
else if button returned of result is "Pictures" then
tell application "iPhoto" to activate
  end tell
else
tell application "Mail" to activate
  end tell
end if

Are the “tell application…” lines correct? Do the app names need to quotes?

If you use the syntax

tell application "xx" to

you must remove the end tell lines.
With keywords like activate, quit, launch the application can be used as a direct argument e.g.

activate application "iPhoto"

A better syntax of your script is


set b to button returned of (display dialog "What is the task?" buttons {"Music", "Pictures", "Mail"})
if b is "Music" then
    activate application "iTunes"
else if b is "Pictures" then
    activate application "iPhoto"
else
    activate application "Mail"
end if

Ah, I see… because of the word “to”. If i were to give a series of tell commands such as:


tell application "Finder"

activate
move selection to folder "Moved" of disk "MacHD"

end tell

THEN I would need the end tell because I didn’t use tell… to. Makes sense. Thanks a ton!