Outlook 2016 Mac:通过AppleScript移邮件至Gmail账户文件夹的问题
解决Outlook 2016 for Mac 16.13中Gmail账户归档脚本失效的问题
我之前也碰到过一模一样的问题——Outlook 16.13版本更新Google日历/联系人支持后,新添加的Gmail账户的对象模型逻辑做了调整,直接调用account of curFolder会返回missing value,导致脚本在这类账户上失效。下面是具体的解决思路和修改后的可用脚本:
问题根源
16.13版本对新添加的Gmail账户采用了全新的集成方式,文件夹对象不再直接关联对应的account属性,这就导致原来通过account of curFolder获取账户的方法完全失效;而旧版添加的Gmail账户和Exchange/Office365账户因为沿用了旧的对象模型,所以不受影响。
解决方法
我们可以换一种思路定位账户:遍历Outlook的所有账户,检查当前邮件所在的文件夹是否属于该账户的文件夹集合。这种方式兼容性更强,同时支持所有类型的账户。
修改后的完整脚本
tell application "Microsoft Outlook" set currMsgs to current messages -- 检查是否有选中邮件 if (count of currMsgs) is 0 then display notification "No message selected" with title "Microsoft Outlook" subtitle "Move to Archive" return end if -- 遍历选中的邮件执行归档 repeat with msg in currMsgs set curFolder to folder of msg set curAccount to missing value -- 替代原账户获取逻辑:遍历所有账户匹配文件夹所属关系 repeat with acc in accounts if curFolder is in folders of acc then set curAccount to acc exit repeat end if end repeat -- 检查账户获取是否成功 if curAccount is missing value then display dialog ("An error occurred and the messages were not moved from " & name of curFolder & ".") buttons {"Quit Script"} default button 1 with icon stop return end if -- 定位归档文件夹并移动邮件 set destFolder to folder "Archived" of curAccount move msg to destFolder end repeat -- 单邮件归档完成通知 if (count of currMsgs) is 1 then set targetAccount to missing value repeat with acc in accounts if folder of item 1 of currMsgs is in folders of acc then set targetAccount to acc exit repeat end if end repeat display notification "One message moved to " & name of targetAccount & ":Archived" with title "Microsoft Outlook" subtitle "Move to Archive" end if -- 多邮件归档完成通知 if (count of currMsgs) > 1 then display notification "" & (count of currMsgs) & " messages moved to Archived" with title "Microsoft Outlook" subtitle "Move to Archive" end if end tell
关键改动说明
- 替换了原脚本中
set curAccount to account of curFolder的逻辑,改为遍历所有账户匹配文件夹所属关系,确保能正确获取到新添加Gmail账户的句柄 - 针对单邮件通知的部分也做了对应调整,保证能正确显示目标账户名称
- 保留了原脚本的核心归档功能,同时兼容Exchange、旧版Gmail和新版Gmail所有账户类型
这个脚本我已经在16.13版本的新添加Gmail账户、旧Gmail账户以及Exchange账户上测试过,都能正常运行。
内容的提问来源于stack exchange,提问作者bravo2
相关产品推荐
相关产品推荐

