Applescript&;邮件规则
我正试图在Mac Mail中设置的规则内执行以下Applescript。我在iMac上运行OS 10.10.1 Yosemite。我的规则查找我每天收到的特定电子邮件,然后指示Mail执行我的Applescript。当我手动突出显示电子邮件并单击“应用规则”时,该规则非常有效;然而,当我早上启动电脑并收到当天的第一封邮件时。Applescript程序陷入了永无止境的循环,菜单栏上出现的旋转图标就是明证。顺便说一句:我的自动程序工作得很好。我的想法是,当Mail下载我所有的邮件时,Applescript在尝试执行时会感到困惑????有什么建议吗??哦,我是新手…谢谢Applescript&;邮件规则,applescript,Applescript,我正试图在Mac Mail中设置的规则内执行以下Applescript。我在iMac上运行OS 10.10.1 Yosemite。我的规则查找我每天收到的特定电子邮件,然后指示Mail执行我的Applescript。当我手动突出显示电子邮件并单击“应用规则”时,该规则非常有效;然而,当我早上启动电脑并收到当天的第一封邮件时。Applescript程序陷入了永无止境的循环,菜单栏上出现的旋转图标就是明证。顺便说一句:我的自动程序工作得很好。我的想法是,当Mail下载我所有的邮件时,Applescr
tell application "System Events"
tell process "Mail"
-- Select the Print menu item
click (first menu item of menu "File" of menu bar 1 whose name begins with "Print")
tell window 1
-- Wait until the print sheet appears
repeat until sheet 1 exists
end repeat
tell sheet 1
-- Click the PDF button
click menu button "PDF"
-- Select the PDF to SBS Dropbox menu item
click (first menu item of menu 1 of menu button "PDF" whose name begins with "PDF to SBS Dropbox")
end tell
end tell
end tell
end tell
首先,需要使用邮件规则调用的Applescript处理程序:
on perform mail action with messages theMessages for rule theRule
在该处理程序中,您可以访问符合邮件规则条件的邮件,并执行任何您喜欢的操作。以下是可用于添加代码的框架:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with thisMessage in theMessages
-- place your code here
end repeat
end tell
end perform mail action with messages
end using terms from
在您的特殊情况下,我认为我们可以尝试将您的代码放入重复循环中,让mail在执行前打开邮件,在打印后关闭:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
-- walk through all matching messages
repeat with thisMessage in theMessages
-- open the message
set openedMail to open thisMessage
-- perform your UI scripting
tell application "System Events"
tell process "Mail"
-- Select the Print menu item
click (first menu item of menu "File" of menu bar 1 whose name begins with "Print")
tell window 1
-- Wait until the print sheet appears
repeat 30 times
if sheet 1 exists then exit repeat
delay 0.5
end repeat
tell sheet 1
-- Click the PDF button
click menu button "PDF"
-- Select the PDF to SBS Dropbox menu item
click (first menu item of menu 1 of menu button "PDF" whose name begins with "PDF to SBS Dropbox")
end tell
end tell
end tell
end tell
-- close the message
close openedMail
end repeat
end tell
end perform mail action with messages
end using terms from
它还没有测试!我防止脚本在尝试访问打印页时以无限循环运行
试试看!祝你愉快,迈克尔/汉堡谢谢。你的第一个建议导致了另一个连续循环;其中Mail打开了电子邮件,但未完成任务。然后它取消了,并一次又一次地尝试。第二个建议似乎很有效;但是,它不会在任务完成后关闭电子邮件。这不是问题,但我想你想知道。明天早上当我收到周五的新邮件时,我会看看它是如何工作的。再次感谢。。。