Nov 29, 2011

Messing around with AppleScript

Ever since I made the decision to buy a Mac I've wanted to mess around with apples excellent application scripting system (i.e AppleScript). I finally got around to it today and now am throughly impressed by the number things you can accomplish with it.

Anyway as my sort of "hello world" task, I've written up this little script down here which will "speak" or "Read Aloud" the number of unread messages in your "Mail" (assuming you're using - which you should) and the sender and subject of each unread message. This combined with the impressive new text-to-speech voices in OSX Lion makes it rather useful. I will now have all my emails read to me by a sexy indian lady on my computer (aka sangeetha!)

I did some googling around but didn't find anybody else doing this so I figured I'd share it here.

the script!
tell application "Mail"
 set unreadCount to unread count of inbox
 set theMessages to (messages of inbox whose read status is false)
 if unreadCount > 0 then
  say ("you have," & unreadCount & ",new messages")
  repeat with msg in theMessages
   say ("message, from" & (sender of msg) & ". Saying" & (subject of msg))
   delay 1
  end repeat
  say "you have no, new messages."
 end if
end tell
I've also compiled it into an alfred extension which you can download from here cheers