January 30, 2008
I love my Mac Applescript + Mail.app
Normally I just enjoy computing more that I have switched to the mac platform. Mainly because all of the software just seems to be so well thought out. So much of my experience with Windows was whatever it took to get the job done as quickly as possible so we can move on to the next one. With the Mac there are just certain elements that make me fell all giddy inside as a technology enthusiast and software developer. One of these little moments came to me in the form of a post on MacOSXHints.com.
It was a very simple AppleScript something I have messed with in the past for creating some things I thought were missing in the Finder like a directory up button and directory refresh button on my Finder windows. But I hadn’t really thought of it in the same way I might think about a unix shell script. It just doesn’t seem structured enough to do anything really useful. Until I saw this tip, the jest of which was to announce the name of an incoming mail message sender instead of a simple incoming mail alert.
With very little modification here is my version of the script.
using terms from application "Mail"
on perform mail action with messages newMessages
repeat with newMessage in newMessages
tell application "Mail"
set senderName to (extract name from sender of newMessage)
set mailSubject to (get subject of newMessage)
say "E-Mail from " & senderName
say "Subject " & mailSubject
end tell
end repeat
end perform mail action with messages
end using terms from
I saved this as a compiled application and move to Mail.app where I created a rule called Announce and was able to integrate it with my Address book and tell it to only fire for people who are in my family or friends groups. This means only people I know who send me e-mail all the time will run this script. Next I moved it to the top of the list so no other scripts would run before it. Now when my wife sends me an e-mail that might be of importance instead of hearing a bing and knowing I have some random e-mail that I will look at later I hear that she sent me an e-mail plus the subject so I can decide if it is something I should read or if she is just forwarding me another chain joke e-mail.