0

I am having trouble with this in applescript:

display dialog "Open Which Application" buttons {"Chrome", "AppleScript", "Textedit"} 
set the button_pressed to the button returned of the result
if the button_pressed is "Chrome" then
Open application "Google Chrome"-- action for 1st button goes here
if the button_pressed is "Applescript" then
Open application "Applescript Editor"-- action for 2nd button goes here
if the button_pressed is "Textedit" then
Open application "Textedit"-- action for 3rd button goes here
end

It keeps saying SYNTAX ERROR: Expected “else”, etc. but found end of script.

What should I do

0

2 Answers 2

0

You have three if statements, but you only end one of them.

What you probably want here is else if:

display dialog "Open Which Application" buttons {"Chrome", "AppleScript", "Textedit"}
set the button_pressed to the button returned of the result
if the button_pressed is "Chrome" then
    open application "Google Chrome" -- action for 1st button goes here
else if the button_pressed is "Applescript" then
    open application "AppleScript Editor" -- action for 2nd button goes here
else if the button_pressed is "Textedit" then
    open application "TextEdit" -- action for 3rd button goes here
end if

(Also, you're really supposed to use end if, not just end, but AppleScript Editor will fix that for you.)

Alternatively, you could end each one:

display dialog "Open Which Application" buttons {"Chrome", "AppleScript", "Textedit"}
set the button_pressed to the button returned of the result
if the button_pressed is "Chrome" then
    open application "Google Chrome" -- action for 1st button goes here
end if
if the button_pressed is "Applescript" then
    open application "AppleScript Editor" -- action for 2nd button goes here
end if
if the button_pressed is "Textedit" then
    open application "TextEdit" -- action for 3rd button goes here
end if

However, the cases are obviously mutually exclusive, so there's not reason not to use else if instead.

If it helps, type the lines in one by one and see how AppleScript Editor is indenting them:

display dialog "Open Which Application" buttons {"Chrome", "AppleScript", "Textedit"} 
set the button_pressed to the button returned of the result
if the button_pressed is "Chrome" then
    Open application "Google Chrome"-- action for 1st button goes here
    if the button_pressed is "Applescript" then
        Open application "Applescript Editor"-- action for 2nd button goes here
        if the button_pressed is "Textedit" then
            Open application "Textedit"-- action for 3rd button goes here
        end

That should make it obvious what's wrong.

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

display dialog "Open Which Application" buttons {"Chrome", "AppleScript", "Textedit"}
set the button_pressed to the button returned of the result
if the button_pressed is "Chrome" then tell application "Google Chrome" to activate -- action for 1st button goes here 
if the button_pressed is "Applescript" then tell application "AppleScript Editor" to activate -- action for 2nd button goes here 
if the button_pressed is "Textedit" then tell application "TextEdit" to activate -- action for 3rd button goes here end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.