[英]Why doesn't this simple applescript work any more in ML mail.app (as a rule)
它仅在您右键单击邮件并选择“运行规则”时有效,而对传入消息无效(无交互)。
无论是传入还是手动运行,都会显示第一个对话框,但是只有手动运行时,才会显示第二个对话框(带有id)。 console.log中未显示任何内容
有任何想法吗?
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with theMessage in theMessages
display dialog "inside"
set theId to id of theMessage
display dialog "the id is " & theId
end repeat
end tell
end perform mail action with messages
end using terms from
更新:我在周围添加了一个try catch块
set theId to id of theMessage
这是我得到的错误:
Can't get class mssg 1 of class mbxp "Incoming POP messages" of class mact "Telenet". Invalid index. -1719
知道这意味着什么吗? 手动应用规则时,我没有收到错误消息。
更新2:好的,我发现传入的消息还没有ID。 这是一个问题,因为我想将电子邮件保存到磁盘:
set theEmail to (do shell script "mdfind -onlyin ~/Library/Mail \"kMDItemFSName = '" & theId & ".emlx'\"")
set archiveName to theId & "-" & (extract address from theMessage's sender) & ".emlx"
set saveLocation to "Users:wesley:Documents:Incoming:"
do shell script "cp '" & theEmail & "' '" & POSIX path of saveLocation & "';"
有没有办法解决?
如我的评论中所承诺的,这是一个AppleScript,可将邮件消息的subject
, id
和message id
到〜/ Desktop / log.txt中。
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
try
repeat with theMessage in theMessages
LogText("subject: " & (theMessage's subject as string))
LogText("id: " & (theMessage's id as string))
LogText("message id: " & (theMessage's message id as string))
LogText("")
end repeat
on error errorText number errorNumber
tell application "Mail" to display alert ("Error: " & errorNumber) message errorText
return
end try
end perform mail action with messages
end using terms from
on LogText(theText)
tell application "Finder"
set logPath to (path to the desktop as text) & "log.txt"
try
set writeText to open for access file logPath with write permission
set currentDateAsString to do shell script "date +\"%Y-%m-%d %T\""
write (currentDateAsString & " " & (theText as text) & return) to writeText starting at ((get eof writeText) + 1)
close access writeText
on error errorText number errorNumber
close access writeText
error errorText number errorNumber
end try
end tell
end LogText
我也在运行OS X 10.8.2和Mail 6.2。 就像我说的那样,我很惊讶,但是通过邮件规则触发上面的AppleScript与选择菜单“应用规则”时的传入消息一样有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.