2013-03-01 39 views
0

我有這個麻煩的AppleScript:Applescript語法錯誤「Expected」else「等,但發現腳本結束。」

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 

口口聲聲說語法錯誤:應爲「其他」等卻發現劇本的結尾。

我應該怎麼做

回答

0

你有三個if語句,但你只end其中之一。

你可能想在這裏什麼是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 

(另外,你真的應該會使用end if,不只是end,但AppleScript的編輯器將修復你)

或者,你可以每個end

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 

然而,案件顯然是米非常獨特,所以沒有理由不使用else if

如果有幫助,通過一種類型在一個線路,看到的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 

這應該很明顯出了什麼問題。

0

嘗試:

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 
相關問題