Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
If statement AppleScript:如果命令未执行_If Statement_Applescript - Fatal编程技术网

If statement AppleScript:如果命令未执行

If statement AppleScript:如果命令未执行,if-statement,applescript,If Statement,Applescript,我是AppleScript的初学者,所以我真的知道的不多。我一直试图让用户从一系列情况中进行选择,然后根据他们的选择做出适当的反应。但是,我遇到了一些问题: 脚本运行,但不显示通知。 有没有比链接大量IF语句更好的方法? 附言:我还没有完成整个剧本 on run choose from list {"Thunderstorm", "Flood", "Heatwave", "Hazmat"} with prompt "Please select one of the emergency s

我是AppleScript的初学者,所以我真的知道的不多。我一直试图让用户从一系列情况中进行选择,然后根据他们的选择做出适当的反应。但是,我遇到了一些问题:

脚本运行,但不显示通知。 有没有比链接大量IF语句更好的方法? 附言:我还没有完成整个剧本

on run
    choose from list {"Thunderstorm", "Flood", "Heatwave", "Hazmat"} with prompt "Please select one of the emergency situations below" without multiple selections allowed and empty selection allowed
    return the result as string
    if string is Thunderstorm then display notification "hello"
end run

您对正在查看的示例代码做了一些很好的猜测;但其中一些猜测是错误的。随着时间的推移,您将更好地了解AppleScript的工作原理

通过使用引号将情景名称的文本括起来,可以在“选择自”列表行中正确输入情景名称作为字符串。但在检查是否是雷雨时,不要用引号括住文本。AppleScript正在查找名为雷雨的变量的内容,而不是查看文本“雷雨”的字符串

以字符串形式返回结果不会创建名为string的变量,而是结束名为run的处理程序,将结果以文本字符串形式返回给名为run的任何代码。要将“从列表中选择”的结果指定给变量,请使用类似于将结果设置为字符串的内容

下面是一个示例,说明如何更好地使用代码:

on run
    --get the situation we're dealing with
    choose from list {"Thunderstorm", "Flood", "Heatwave", "Hazmat"} with prompt "Please select one of the emergency situations below" without multiple selections allowed and empty selection allowed
    copy the result as string to theSituation

    --Thunderstorms require that the user be immediately notified
    if theSituation is "Thunderstorm" then display notification "hello"
end run
由于您将其作为运行处理程序,您可能不想返回任何结果,因为您很少调用运行处理程序。但如果您确实需要返回结果,则在结束运行之前处理程序的最后一行是:

return theSituation
您可以四处寻找适合您需要的AppleScript教程。苹果有自己的优势

可以使用IF/else IF/else IF链接IF语句:

on run
    --get the situation we're dealing with
    choose from list {"Thunderstorm", "Flood", "Heatwave", "Hazmat"} with prompt "Please select one of the emergency situations below" without multiple selections allowed and empty selection allowed
    copy the result as string to theSituation

    --Thunderstorms require that the user be immediately notified
    if theSituation is "Thunderstorm" then
        display notification "hello"
    else if theSituation is "Flood" then
        display notification "hike pants"
    else if theSituation is "Heatwave" then
        display notification "Play Bing Crosby"
    else if theSituation is "Hazmat" then
        display notification "Use highway 183"
    end if
end run
AppleScript中没有开关/案例控制结构