【问题标题】:How to open an email message using applescript?如何使用applescript打开电子邮件?
【发布时间】:2009-06-19 10:13:42
【问题描述】:

我正在编写一个小applescript,它检索查看器中的所有“未读”消息并循环它们。

我有两个目标要完成:

  1. 我需要获取每封邮件的主题并执行正则表达式以查看它是否适合第 2 步(例如:获取主题为 {.*} 的电子邮件)

  2. 我需要在单独的窗口中打开每条消息,4 秒后,我需要关闭该窗口并继续处理下一条消息

你知道怎么做吗?

提前致谢。

【问题讨论】:

    标签: applescript email


    【解决方案1】:

    以下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】:

      对于正则表达式——如果您在自己的机器上运行脚本,或者可以捆绑分发它,您可以使用 Satimage 的 Smile 扩展 (http://www.satimage.fr/software/en/downloads/index.html),它将正则表达式添加到 Applescript。

      【讨论】:

        【解决方案3】:

        我知道您已经有了答案,但您是否研究过 Automator?对于诸如此类的大多数标准脚本,如果您对 AppleScript 不太熟悉,则可能不会那么痛苦。它不是很“程序化”,但速度很快,而且您会花更少的时间进行调试。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-02-04
          • 2012-01-30
          • 1970-01-01
          • 2020-12-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多