I am trying to code an AppleScript with a dialog box that has multiple buttons, which each execute different commands. My problem is that AppleScript Editor detects either "end if" or "else if" as a syntax error, as per the title.
For example:
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 Editor displays the error " : Expected end of line, etc. but found “else if”." :预期的行尾等,但找到”否则”。
Is there something I'm doing wrong?
AppleScript's conditionals have two formats, a simple single-line format:
if condition then statement
and a multiline format:
if condition then
statement
end if
If you want to use multiple statements or have multiple conditions ( else if
), you must use the multiline format:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.