Applescript for Reading Email to me

I want a script that will take my gmail account, find new emails, and read them to me using the "say" function and not display anything on the screen. Is that possible?

Mac OS X (10.7.1)

Posted on Aug 29, 2011 1:58 PM

Reply
10 replies

Aug 29, 2011 4:03 PM in response to derekshull

Possible? it's trivial, but if your inbox is anything like mine it's going to get annoying, really quickly 🙂


tell application "Mail"

set unreadMessages to (get every message of mailbox "INBOX" of account "Gmail" whose read status is false)

repeat with eachMessage in unreadMessages

say (get content of eachMessage)

end repeat

end tell

Aug 29, 2011 7:17 PM in response to Camelot

Is there a way to mark it as read after it has read it to me? Also (and I know I'm getting technical but this is for a friend who can't see) is there a way to make it say something in between the messages so that he will know the difference between messages? Like have it say "Message 1: <says message>" "Message 2: <says message>" and so forth? Thanks so much for the help this was great!!!!!

Aug 29, 2011 7:37 PM in response to derekshull

Nevermind! I got it to do everything but mark the message as read in the inbox. Is that possbile? Plus with his gmail he has different folders set up so not all the new messages go to the inbox is there a way to get it to read him those messages that are in his subfolders as well. They skip them inbox and go straight to labels or folders in the Mail app. Thanks again!

Aug 29, 2011 9:15 PM in response to derekshull

Yes, it's all possible.


mark the message as read in the inbox


just put:


set read status of eachMessage to true


inside the repeat loop, after the say statement.


is there a way to get it to read him those messages that are in his subfolders as well

Sure, you asked for the inbox, so that's what I showed you. Just substitute any other mailbox name... e.g. 'every message of mailbox "blah" of account "Gmail"...' You could even use 'every message of every mailbox...' if you want.

Aug 30, 2011 7:36 PM in response to derekshull

Also I have this code:


display dialog "Enter Mailbox To Check:" default answer ""

set s to text returned of result

if s = "Inbox" then s = "INBOX"

tell application "Mail"

set unreadMessages to (get every message of mailbox (s) of account "Gmail" whose read status is false)

repeat with eachMessage in unreadMessages

say "Subject."

say (get subject of eachMessage)

say "Message."

say (get content of eachMessage)

set read status of eachMessage to true

end repeat

end tell


I don't think this:

if s = "Inbox" then s = "INBOX"


is working though. If I put in "Inbox" I want it to switch it to "INBOX" instead so it'll tell me his inbox. Thanks!

May 22, 2012 9:07 AM in response to derekshull

if it doesn't have any new message what do i need to put in to make it say "no new messages" if there are no new messages? Thanks!

A simple if statement:


...

set unreadMessages to (get every message of mailbox (s) of account "Gmail" whose read status is false)

if count unreadMessages = 0 then

say "No new messages"

else

repeat with eachMessage in unreadMessages


-- speak stuff goes here

end repeat

end if

...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript for Reading Email to me

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.