2016-10-03 72 views
1

AppleScript初學者在這裏,仍然苦於基本的語法。AppleScript清單及其子句

這工作:

tell application "Mail" 
    set flagged to messages of inbox whose flagged status is true 
    log count of flagged 
end tell 

這不起作用:

tell application "Mail" 
    set msgs to messages of inbox 
    set flagged to msgs whose flagged status is true 
    log count of flagged 
end tell 

爲什麼? (我懷疑它是在逃避我一個簡單的語法規則)

回答

2

當你寫set msgs to messages of inbox,你真正想說的是set msgs to GET messages of inbox作爲AppleScript的自動執行命令get如果你不告訴它,否則,其結果是(消息引用)一個AppleScript列表,如:

{message id 123 of mailbox "Inbox" ..., message 124 of mailbox "Inbox" ...} 

然而,whose查詢(引用)只能在應用對象的工作,而不是AppleScript的列表,如:

every item of {1, 2, 3, 4, 5} where it > 3 
-- error "Can’t get {1, 2, 3, 4, 5} whose it > 3." number -1728 

請嘗試改爲:

tell application "Mail" 
    set msgs to a reference to messages of inbox 
    set flagged to msgs whose flagged status is true 
    log count of flagged 
end tell