Syntax Applescript语法错误“;预期“;else”;,等,但找到了脚本的结尾。”;

Syntax Applescript语法错误“;预期“;else”;,等,但找到了脚本的结尾。”;,syntax,applescript,Syntax,Applescript,我在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 fo

我在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
它一直在说语法错误:应该是“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编辑器将为您解决这一问题。)

或者,您可以
结束
每一项:

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
这会让问题变得显而易见。

试试:

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