Using AppleScript with OE to announce new mail
Using AppleScript with OE to announce new mail
- Subject: Using AppleScript with OE to announce new mail
- From: Mr Tea <email@hidden>
- Date: Thu, 11 Oct 2001 23:05:53 +0100
I'm sure that some contributors to this list will remember the friendly way
that Cyberdog could be set to announce new mail using the Mac's built in
speech functions. I liked that, and inspired by the discovery that there is
a shareware AppleScript solution for doing the same kind of thing with
Outlook Express, I thought I'd have a crack at it myself.
The results of my labours are reproduced below.
The script, as is, is not particularly portable, depending as it does on
specific message folders and subfolders that I have set up in OE ("Mr Tea's
Inbox", which receives all non-list mail to my mac.com address, and "Lists",
which contains a separate sub-folder for each of the lists I subscribe to).
The script is saved as a stay-open applet, which is run by a script attached
to OE's 'send & receive all' schedule. Another script that runs when OE is
shut down tells the applet to quit. Making the script an applet (rather than
a compiled script that OE itself runs) seemed the best way to avoid
problems. It also means that the script can have it's memory allocation
upped, which is advisable when using speech.
Most of the script's complexity lies not in counting the new messages, but
in generating a grammatically pleasing string to pass on to the speech
synthesiser.
The spoken text also contains a smattering of embedded commands (enclosed in
double square brackets) which provide emphasis where desirable, or
separation between words that tend to run together. Trinoids is my favoured
voice, mainly because it is deliberately synthetic, rather than
unconvincingly human. I welcome any comments and criticisms, and please feel
free to adapt the script for your own use if it seems worthwhile.
Anti-munging notes: any line that butts up to the left margin and does not
begin with the words 'on' or 'end' has been wrapped, and needs to be
re-appended to the end of the previous line; and where I used the 'option-L'
or 'option-return' character to force-wrap a line in the script, I have
noted this in square brackets - either replace these with your own option-L
keystroke, or unwrap the lines.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on run
delay 30
tell application "Finder"
set activeApp to creator type of (application file of processes
whose frontmost is true)
end tell
if activeApp is not "MSNM" then my AnnounceMail()
end run
on AnnounceMail()
tell application "Outlook Express"
set messageCount to 0
set listMessageCount to 0
set folderList to every folder whose name is not [option-L]
"Outbox" and name is not "Sent Items" and name is not [option-L]
"Deleted Items" and name is not "Drafts" and name is not "Lists"
repeat with thisFolder in folderList
set messageCount to messageCount + (unread message count of
thisFolder)
end repeat
set subFolderList to every folder of folder "Lists"
repeat with thisSubFolder in subFolderList
set listMessageCount to listMessageCount + (unread message count
of thisSubFolder)
end repeat
set messageTotal to messageCount + listMessageCount
if messageTotal > 0 then
if messageTotal = listMessageCount then
if listMessageCount > 1 then
set theWords to "You have " & messageTotal & " [[slnc
50]]new [[emph ++]]list messages."
else
set theWords to "You have 1 [[slnc 50]]new [[emph
++]]list message."
end if
else if messageTotal > listMessageCount and listMessageCount > 0
then
if listMessageCount > 1 then
set theWords to "You have " & messageTotal & [option-L]
" [[slnc 50]]new messages, including " &
listMessageCount & " [[emph ++]]list messages."
else
set theWords to "You have " & messageTotal & [option-L]
" [[slnc 50]]new messages, including 1 list
message."
end if
else if listMessageCount = 0 then
if messageTotal > 1 then
set theWords to "You have " & messageTotal & " [[slnc
50]]new messages."
else
set theWords to "You have 1 [[slnc 50]]new message."
end if
end if
set myInbox to folder "Mr Tea's Inbox"
set tMail to (messages whose read status is untouched) of
myInbox
set tCount to count of items in tMail
set mCount to 0
if tCount > 0 then
set senderNames to ""
if tCount = 1 then
set theWords to theWords & " Mister [[emph ++]]Tea has
mail from " & [option-L]
display name of sender of item 1 of tMail & "."
else
repeat with theMessage in tMail
set mCount to mCount + 1
if mCount < tCount then
set senderNames to [option-L]
(senderNames & display name of sender of
theMessage as string) & ", "
else
set senderNames to [option-L]
(senderNames & " and " & display name of
sender of theMessage as string) & "."
end if
end repeat
set theWords to theWords & [option-L]
" Mister [[emph ++]]Tea has mail from " &
senderNames
end if
end if
say theWords using "Trinoids"
end if
end tell
end AnnounceMail
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Regards
Mr Tea
--
Brew of the day: [ ibid ]
Visit the Tea Room at:
http://homepage.mac.com/mrtea/tearoom.html