derekshull

Q: 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:59 PM

Close

Q: Applescript for Reading Email to me

  • All replies
  • Helpful answers

  • by Camelot,Solvedanswer

    Camelot Camelot Aug 29, 2011 4:03 PM in response to derekshull
    Level 8 (47,305 points)
    Mac OS X
    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

  • by derekshull,

    derekshull derekshull Aug 29, 2011 7:17 PM in response to Camelot
    Level 1 (0 points)
    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!!!!!

  • by derekshull,

    derekshull derekshull Aug 29, 2011 7:20 PM in response to derekshull
    Level 1 (0 points)
    Aug 29, 2011 7:20 PM in response to derekshull

    Or maybe instead have it say "Subject: <says subject> Message: <says Message>" for each message...idk what do you think?

  • by derekshull,

    derekshull derekshull Aug 29, 2011 7:37 PM in response to derekshull
    Level 1 (0 points)
    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!

  • by Camelot,

    Camelot Camelot Aug 29, 2011 9:15 PM in response to derekshull
    Level 8 (47,305 points)
    Mac OS X
    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.

  • by derekshull,

    derekshull derekshull Aug 30, 2011 7:46 AM in response to Camelot
    Level 1 (0 points)
    Aug 30, 2011 7:46 AM in response to Camelot

    I have a folder called Work but when I replaced INBOX with Work it gave me an error :-/

  • by derekshull,

    derekshull derekshull Aug 30, 2011 7:32 PM in response to derekshull
    Level 1 (0 points)
    Aug 30, 2011 7:32 PM 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!

  • by derekshull,

    derekshull derekshull Aug 30, 2011 7:36 PM in response to derekshull
    Level 1 (0 points)
    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!


  • by JamesWhite,

    JamesWhite JamesWhite May 22, 2012 6:34 AM in response to derekshull
    Level 1 (4 points)
    May 22, 2012 6:34 AM in response to derekshull

    Derek, try this

     

    if s = "Inbox" then

       set s to "INBOX"

    end if

     

    Cheers

  • by Camelot,

    Camelot Camelot May 22, 2012 9:07 AM in response to derekshull
    Level 8 (47,305 points)
    Mac OS X
    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

    ...