Speak the sender of a mail item

Mar 06, '03 09:29:00AM

Contributed by: porkchop_d_clown

Here's a quick script to speak the name of the person sending you e-mail. I've seen scripts like this for entourage, but never for Apple's Mail.app. To use it, paste it into Script Editor, save, and create a mail rule that acts on every message and add it to the top of your list of mail rules. Set the action to "Run AppleScript" and choose your new script as the target.

on perform_mail_action(info)
  tell application "Mail"
    set theMessages to |SelectedMessages| of info
    repeat with thisMessage in theMessages
    set AppleScript's text item delimiters to {""}
    set thisSender to sender of thisMessage as string
    set quotepos to offset of "\"" in thisSender
      if (quotepos is not 0) then
        set thisSender to (text items (quotepos + 1) through -1) ¬
          of thisSender as string
        set quotepos to offset of "\"" in thisSender
        if (quotepos is not 0) then
          set thisSender to (text items 1 through (quotepos - 1)) ¬
            of thisSender as string
        end if
      else
        set atpos to offset of "@" in thisSender
        if (atpos is not 0) then
          set thisSender to (text items 1 through (atpos - 1)) ¬
            of thisSender as string
        end if
        set brkpos to offset of "<" in thisSender
        if (brkpos is not 0) then
          set thisSender to (text items (brkpos + 1) through -1) ¬
            of thisSender as string
        end if
      end if
      tell application "Finder" to say "Mail from " & thisSender
    end repeat
  end tell
end perform_mail_action
[robg adds: This worked as described ... see also this hint which explains how to speak the entire contents of messages.]

Comments (34)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030304111345916