你有三个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 Editor 会为你解决这个问题。)
或者,您可以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 Editor 是如何缩进它们的:
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
这应该很明显出了什么问题。