Speak Unread Mail Summary
This script will speak a summary of your unread mail in Mac OS X’s Mail application. In Panther’s Mail.app you can have an AppleScript run as part of a rule - so you can effectively have your computer announce who your mail is from and what the subjects are as it arrives - without having to even switch to the Mail app. You can also refine your rule so that the script is only executed for certain Mail Accounts, or whatever criteria you please.
tell application “Mail”
repeat with thisAccount in every account
set thisInBox to mailbox named “INBOX” of thisAccount
set thisUnreadCount to unread count of thisInBox
if thisUnreadCount is not 0 then
set unreadMessages to (messages of thisInBox whose read status is false)
if thisUnreadCount > 1 then
set pluralText to “s”
set verbText to “are”
else
set pluralText to “”
set verbText to “is”
end if
set speechCountText to “There ” & verbText & ” ” & thisUnreadCount & ” message” & pluralText & ” in ” & (name of thisAccount) & “.”
say speechCountText
repeat with i from 1 to number of items in unreadMessages
set thisMessage to item i of unreadMessages
set theSender to sender of thisMessage
set savedTextItemDelimiters to AppleScript’s text item delimiters
try
set AppleScript’s text item delimiters to {”<"}
set realName to (first text item of (theSender as string))
--finally, reset the text item delimiters:
set AppleScript's text item delimiters to savedTextItemDelimiters
on error m number n from f to t partial result p
log ("Error: " & m & number)
--also reset text item delimiters in case of an error:
set AppleScript's text item delimiters to savedTextItemDelimiters
--and resignal the error: error m number n from f to t partial result p
end try
set messageSpeechText to "From: " & realName & ". Title: " & subject of thisMessage
say messageSpeechText
end repeat
end if
end repeat
end tell
Comments are closed!