用于计算收件箱中邮件的AppleScript失败,显示“无法获取邮箱”


1

这是我第一次尝试AppleScript程序,遇到了可耻的失败:

tell application "Mail"
    tell mailbox "INBOX"
        count messages
    end tell
end tell

它已编译,但是当我运行它时,我收到了错误消息

error "Mail got an error: Can’t get mailbox \"INBOX\"." number -1728 from mailbox "INBOX"

有人可以告诉我出了什么问题吗?如果有一个AppleScript的简短介绍,是为那些习惯编程的人写的吗?

Answers:


2

你期望应该是语法的错误是可以理解的。

每个帐户都有自己的邮箱名为“INBOX”

在邮件中,邮箱 收件箱 是对顶级收件箱的引用,该收件箱显示名为“INBOX”的所有其他收件箱的内容

2个例子:

例1

tell application "Mail"
    set inboxes to first mailbox of every account whose name is "INBOX"
    set messageCount to 0
    repeat with i from 1 to number of items in inboxes

        set this_item to item i of inboxes
        if this_item is not missing value then
            set thisCount to (count of (messages of this_item))
            set messageCount to thisCount + messageCount
            log thisCount
        end if
    end repeat

end tell
log messageCount

例2

tell application "Mail"
    set messageCount to (count of (messages of inbox))
end tell

log messageCount

两者都返回并记录相同的总数。

但是示例1还记录了每个“INBOX”的个人计数

一个良好的开始是读经: AppleScript的基本小号


1
tell application "Mail"
    -- This returns count of messages across all inboxes
    set countA to count (messages of inbox)

    set countB to count (messages of mailbox "INBOX" of account "david")
end tell

return {countA, countB}

在AppleScript编辑器中,按命令shift o打开应用程序字典。AppleScript 1-2-3和权威指南是很好的起点。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.