如何通过AppleScript在Microsoft Outlook中筛选并显示含指定主题词的邮件
如何通过AppleScript在Microsoft Outlook中筛选并显示含指定主题词的邮件
嗨,我来帮你解决这个问题~你写的脚本确实能正确获取到主题包含"deal"的邮件对象,但只是把它们存在变量里,并没有触发Outlook界面展示这些筛选结果,所以你看不到界面变化。下面给你两种实用的解决方案:
方法一:直接调用Outlook内置筛选功能(推荐)
这个方法和你手动在Outlook里设置筛选的效果完全一样,运行后收件箱会自动显示符合条件的邮件:
tell application "Microsoft Outlook" activate set targetFolder to inbox -- 确保使用默认的消息视图(避免视图不兼容) set current view of targetFolder to view "Messages" -- 应用主题包含"deal"的筛选规则 set filter of targetFolder to "subject contains 'deal'" end tell
运行这段脚本后,你会看到Outlook收件箱直接过滤出所有主题带"deal"的邮件,非常直观。
方法二:选中并高亮显示符合条件的邮件
如果你更倾向于保留原来获取邮件对象的逻辑,只需要补充几行代码,让Outlook界面同步选中状态并定位到邮件:
set theMessages to {} tell application "Microsoft Outlook" activate set theFolder to inbox -- 先切换到收件箱文件夹,确保界面在正确的位置 set current folder to theFolder set theMessages to every message of theFolder whose subject contains "deal" set selected messages to theMessages -- 如果有符合条件的邮件,自动滚动到第一个,方便你查看 if length of theMessages > 0 then reveal item 1 of theMessages end if end tell return theMessages
你原来的脚本缺少activate(激活Outlook)和set current folder to theFolder(切换到收件箱)这两步,所以即使选中了邮件,界面也不会更新。加上这两句后,运行脚本就能看到选中的邮件高亮显示在界面上了。
备注:内容来源于stack exchange,提问作者I P
相关产品推荐
相关产品推荐

