How to open an email message using applescript?

我与影子孤独终老i 提交于 2019-12-05 10:18:31

The following applescript works for me, but I'm not sure how to do the regex matching. You can use the unix 'grep' function with applescript's 'do shell script' command, but I'm no expert in how to use grep properly. I'll leave that for someone else to answer.


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

For regexes -- If you're running the script on your own machine, or can distribute it bundled, you could use Satimage's Smile extension (http://www.satimage.fr/software/en/downloads/index.html) which adds regexes to Applescript.

I know you already have your answer but have you looked into Automator? For most standard scripts such as this, it can be less painful if you aren't too familiar with AppleScript. It's not very 'programmy' but it's quick and you'll spend less time debugging.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!