使用applescript获取邮件主题

时间:2011-10-14 16:56:25

标签: applescript

我正在使用Mail applescript模板编写脚本(文件>模板中的新建>邮件>邮件规则Action.scptd)但似乎模板中的示例似乎不起作用

using terms from application "Mail"
      on perform mail action with messages these_messages for rule this_rule
                tell application "Mail"
                          set the message_count to the count of these_messages
                          repeat with i from 1 to the message_count
                                    set this_message to item i of these_messages
                                    try
                                              set this_subject to (subject of this_message) as Unicode text
                                              if this_subject is "" then error
                                    on error
                                              set this_subject to "NO SUBJECT"
                                    end try
                            say this_subject
                          end repeat
                end tell
      end perform mail action with messages
end using terms from

即使消息有主题,也说“没有主题”。我正在使用OS X 10.7.2和Mail 5.1。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

尝试在delay 3下添加set this_subject to (subject of this_message) as Unicode text。可能是Mail在移动到下一个命令之前没有时间处理消息以获取主题行。

如果这样可行,您可能不需要3秒钟。您可以尝试减少延迟时间。请注意,您可以使用小数,如1.8。

答案 1 :(得分:0)

如果它有帮助的话,我在10.8.2(邮件6.2)下工作了吗?这是我使用的代码:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with eachMessage in theMessages
                try
                    set this_subject to subject of eachMessage
                    if this_subject is "" then error
                on error
                    set this_subject to "No subject."
                end try
                say this_subject
            end repeat
        end tell
    end perform mail action with messages
end using terms from

希望有帮助吗?