簡體   English   中英

AppleScript中的“如果結束” /“否則如果結束”不起作用?

[英]“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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM