0

我在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

它一直说 SYNTAX ERROR: Expected "else" 等,但发现脚本结尾。

我应该怎么办

4

2 回答 2

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
于 2013-03-01T23:44:48.350 回答
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 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

这应该很明显出了什么问题。

于 2013-03-01T23:35:46.967 回答