How to open email using applescript?

I write a small applescript that retrieves all the “unread” messages in the viewer and sings them.

I have two goals:

  • I need to get the subject of each message and run a regular expression to find out if this is suitable for step 2 (for example: receive emails with the subject {. *})

  • I need to open each message in a separate window, and after 4 seconds I need to close this window and go to the next message

Do you know how to do this?

Thanks in advance.

+5
source share
3 answers

applescript, , . unix 'grep' applescript 'do shell script', , grep. - , .


on run
    tell application "Mail"
        set myInbox to mailbox "INBOX" of account 1
        set myMessages to every message of myInbox

        repeat with theMessage in myMessages
            if read status of theMessage is false then

                if my subjectIsInteresting(subject of theMessage) then
                    open theMessage
                    delay 4
                    close window 1
                end if

            end if
        end repeat

    end tell
end run

on subjectIsInteresting(subject)

    -- do some regex magic here

    return true -- for now

end subjectIsInteresting
+2

. script , Satimage Smile (http://www.satimage.fr/software/en/downloads/index.html), Applescript.

+1

I know that you already have your answer, but have you looked at Automator? For most standard scripts like this, this can be less painful if you are not too familiar with AppleScript. It doesn’t really “program”, but it is fast and you will spend less time debugging.

+1
source

All Articles