[英]“end if”/“else if” in AppleScript not working?
我正在尝试使用具有多个按钮的对话框编写AppleScript的代码,每个按钮执行不同的命令。 我的问题是,AppleScript编辑器根据标题检测到“ end if”或“ else if”作为语法错误。
例如:
set dialog to display dialog "Test" buttons {"1","2"}
set pressed to button returned of dialog
if pressed is equal to "1" then activate "Safari"
else if pressed is equal to "2" then beep
end if
AppleScript编辑器显示错误“ 语法错误 :预期的行尾等,但找到”否则”。
我做错了什么吗?
AppleScript的条件格式有两种格式,一种是简单的单行格式:
if condition then statement
和多行格式:
if condition then
statement
end if
如果要使用多个语句或有多个条件( else if
),则必须使用多行格式:
set dialog to display dialog "Test" buttons {"1", "2"}
set pressed to button returned of dialog
if pressed is equal to "1" then
activate "Safari"
else if pressed is equal to "2" then
beep
end if
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.