Applescript 未定义变量结果

Applescript 未定义变量结果,applescript,Applescript,我对AppleScript编码非常陌生,我想知道这段代码出了什么问题。错误是“变量结果未定义”。为什么会发生错误?我的代码如下: display dialog "Hello and welcome to my app!" buttons {"Login", "Quit"} default button 1 if the button returned of the result is "Login" then display dialog "Username:" buttons {"R

我对AppleScript编码非常陌生,我想知道这段代码出了什么问题。错误是“变量结果未定义”。为什么会发生错误?我的代码如下:

display dialog "Hello and welcome to my app!" buttons {"Login", "Quit"} default button 1

if the button returned of the result is "Login" then
    display dialog "Username:" buttons {"Raphi", "Guest"} default button 1 with title      "Choose user"
else
    tell application "My app" to quit
end if
if the button returned of the result is "Raphi" then
display dialog "Password:" default answer "" buttons {"Submit"} with title "Enter    password" with hidden answer
else
display dialog "You have selected guest! Guest is not currenty enabled, please ask     Raphi to enable it. Thank you!" buttons {"OK"}
end if
if the text returned of the result is "123" then
display dialog "Would you like to continue or exit?" buttons {"Continue", "Exit"}
else
display dialog "Incorrect password" buttons {"OK"} default button 1 with icon stop
end if
if the button returned of the result is "OK" then
tell application "My app" to quit
end if
if the button returned of the result is "Continue" then
display dialog ""
else
tell application "My app" to quit
end if

错误出现在最后几个if语句中,它们需要与
else if
绑定在一起,以获得正确的结构来捕获3个可能的按钮选择

另一个调整是将
告诉应用程序“我的应用程序”退出
,改为
返回
。这将退出脚本的执行并将退出它(注意:如果保存为应用程序,将其设置为保持打开状态

这也有助于测试,因为它不会在每次运行脚本时退出脚本编辑器。或者,您可以使用
quit
简化此块,但我认为
return
更干净

见以下修改:

display dialog "Hello and welcome to my app!" buttons {"Login", "Quit"} default button 1

if the button returned of the result is "Login" then
    display dialog "Username:" buttons {"Raphi", "Guest"} default button 1 with title "Choose user"
else
    return
end if

if the button returned of the result is "Raphi" then
    display dialog "Password:" default answer "" buttons {"Submit"} with title "Enter    password" with hidden answer
else
    display dialog "You have selected guest! Guest is not currenty enabled, please ask     Raphi to enable it. Thank you!" buttons {"OK"}
    return
end if

if the text returned of the result is "123" then
    display dialog "Would you like to continue or exit?" buttons {"Continue", "Exit"}
else
    display dialog "Incorrect password" buttons {"OK"} default button 1 with icon stop
end if

if the button returned of the result is "OK" then
    return
else if the button returned of the result is "Continue" then
    display dialog ""
else
    return
end if
请尝试以下方法:

set dialogResult to display dialog ...
然后检查返回值:

if button returned of dialogResult is ... then