将电子邮件正文传递给AppleScript

时间:2010-05-12 15:56:16

标签: email macos applescript

当我收到一封带有“AppleScript”主题的电子邮件时,我设置了Mail来执行AppleScript,我想知道如何将此电子邮件的正文传递给脚本执行。

提前致谢!

1 个答案:

答案 0 :(得分:5)

消息正文可以确定我使用已传递给规则操作的消息的content属性。要执行脚本,请使用run script命令。

以下脚本是一个如何编写AppleScript的示例,该AppleScript可以作为规则操作附加,该操作将以AppleScript形式运行邮件正文:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with theMessage in theMessages
                set theBody to content of theMessage as text
                my executeScript(theBody)
            end repeat
        end tell
    end perform mail action with messages
end using terms from

on executeScript(theScript)
    display alert "Run the following AppleScript?" message theScript buttons {"Cancel", "Run"}
    if button returned of result = "Run" then
        run script theScript
    end if
end executeScript