0

我正在尝试自动化打开通过电子邮件发送的特定链接的过程。

电子邮件中有多个链接,包括一个取消订阅服务的链接,因此打开正确的链接而不是所有链接很重要。

流程将是:

  1. 电子邮件进来并触发规则
  2. 规则查找两个参数:来自地址的电子邮件和电子邮件正文中的关键字(不是链接)
  3. 规则将电子邮件移动到特定邮箱,然后触发 AppleScript
  4. AppleScript 搜索特定 URL 的开头并在浏览器中打开它(我在白天方便时手动查看打开的浏览器选项卡)
  5. 电子邮件标记为已读

这就是我所拥有的无法正常工作的:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail" to set t to paragraphs of the content of eachMessage
            repeat with i in t
                if i starts with "http://www.website.com/specific/link" then tell application "Safari" to open location i
            end repeat
        end repeat
    end perform mail action with messages
end using terms from

关于我可以做些什么来使这个过程有效的任何建议?

4

1 回答 1

0

你应该得到 AppleScript 段落而不是 Mail.app 段落:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with eachMessage in theMessages
            tell application "Mail" to set t to (content of eachMessage) as string -- EDITED
            set t to paragraphs of t -- ADDED
            repeat with i in t
                if i starts with "https://stackoverflow.com/questions/67909907/open-links-sent-in-email-using-applescript" then openLocation(i)
            end repeat
        end repeat
    end perform mail action with messages
end using terms from

on openLocation(theURL)
    tell application "Safari" to open location theURL
end openLocation
于 2021-06-09T20:18:14.473 回答