Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Get unread message count from
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Get unread message count from

Here's a problem which originated on the Carbon list. 

"Get Mail's unread message count so it matches the number on its icon badge in the dock."

What is needed is something fast which works on all kinds of setups.
Can anyone verify #4? 

1. Too slow

tell application "Mail" to count (every message of every mailbox whose read status is false)

2. Doesn't work on all setups:

set sum to 0
tell application "Mail" to set res to unread count of mailboxes
repeat with i in res
set sum to sum + i
end repeat

3. Doesn't work on all setups:

tell application "Mail"
set msgCount to {}
repeat with thisAccount in (every account whose enabled is true)
set end of msgCount to (unread count of every mailbox of thisAccount)
end repeat
end tell

4. Latest version of #2. Can't verify if it works on all setups:

set sum to 0
tell application "Mail"
set alist to every account whose enabled is true
repeat with a from 1 to count of alist
set res to unread count of every mailbox
repeat with i in res
set sum to sum + i
end repeat
end repeat
end tell


Philip Aker
echo email@hidden@nl | tr a-z@. p-za-o.@

Democracy: Two wolves and a sheep voting on lunch.

Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.