AppleScript语法

AppleScript语法,applescript,macos,Applescript,Macos,我知道这是一个草率的代码,但它是: display dialog ("Start Screensaver. Please type: matrix, coffee, waffles, star, water, or fireworks.", default answer "") if text returned of result = "matrix" then set user_choice to "MatrixSaver" else if text returned of result =

我知道这是一个草率的代码,但它是:

display dialog ("Start Screensaver. Please type: matrix, coffee, waffles, star, water, or
fireworks.", default answer "")
if text returned of result = "matrix" then
set user_choice to "MatrixSaver"
else
if text returned of result = "coffee" then
    set user_choice to "Coffee"
else
    if text returned of result = "waffles" then
        set user_choice to "Waffles"
    else
        if text returned of result = "star" then
            set user_choice to "Hyperspace"
        else
            if text returned of result = "water" then
                set user_choice to "LotsaWater"
            else
                if text returned of result = "fireworks" then
                    set user_choice to "Skyrocket"
                else
                    (*do nothing*)
                end if
            end if
        end if
    end if
end if
end if

if (user_choice = null) then (*do nothing*)
else
tell application "System Events"
    set ss to screen saver user_choice
    start ss
end tell
end if
当我试图编译代码时,“默认答案”会突出显示,并显示“预期”)”等,但找到了标识符


有什么想法吗?谢谢。

我相信正确的语法只是

display dialog "Start Screensaver. Please ..." default answer ""

(“启动屏幕保护程序”)
默认答案
参数之间的
导致语法错误。卸下

这不是语法错误,但是变量
user\u choice
在大
if
块之外不存在。如果按编写的方式运行,您将在最后一个
If
块中收到此消息:

未定义变量
user\u choice

您可以通过在
显示对话框
语句之前声明变量来解决此问题

set the user_choice to ""

现在,您可以在代码中的任何位置使用该变量。:)

回答的后半部分不正确AppleScript只有局部(函数)和全局作用域。@fireshadow25当我按照你说的做时,“默认答案”的“默认”被突出显示,程序说它需要一个“,”任何想法?@CodeKid Yeah。除非对表达式求值,否则实际上不需要parenthase。我建议从
显示对话框
语句中删除两个括号。