为什么这个简单的applescript在ML mail.app中不再起作用(通常) [英] Why doesn't this simple applescript work any more in ML mail.app (as a rule)
问题描述
仅当您右键单击邮件并选择运行规则"时,此方法才有效,但对传入消息(无交互)则无效.
It works only when you right click on the mail message and choose "run rules", but not on incoming messages (without interaction).
第一个对话框在进入或手动运行时均显示,但是第二个对话框(带有ID)仅在手动运行时显示.console.log中没有任何显示
The first dialog is shown both when incoming or running manually, but the second dialog (with the id) is only shown when running manually. Nothing is shown in 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
更新:我在
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
有什么意思吗?手动应用规则时我没有收到错误.
Any idea what this means? I don't get the error when applying rules manually.
更新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 & "';"
有什么办法解决这个问题吗?
Is there any way around this?
推荐答案
As promised in my comment, here's an AppleScript that logs Mail messages' subject
, id
, and message id
to ~/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与选择菜单应用规则"时的传入消息一样有效.
I'm also running OS X 10.8.2 and Mail 6.2. As I said, I'm surprised to say this, but triggering the above AppleScript via mail rule works just as well for incoming messages as it does when selecting the menu "Apply Rules".
这篇关于为什么这个简单的applescript在ML mail.app中不再起作用(通常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!