如何用AppleScript批量删除通讯录中带自定义标签的周年纪念日
解决方案
原脚本报错的核心原因是:macOS 通讯录的自定义标签周年纪念不属于系统默认的 anniversary 固定属性,而是归在联系人的 dates 集合下,每个日期条目单独携带 label 标签属性,原脚本的属性路径调用错误导致执行失败。
你可以使用下面的修正版AppleScript完成批量删除操作:
tell application "Contacts" set targetLabel to "MyCustomLabel" -- 替换为你实际的自定义标签名 -- 遍历所有联系人 repeat with eachPerson in people -- 遍历当前联系人的所有日期字段 repeat with eachDate in dates of eachPerson if label of eachDate starts with targetLabel then delete eachDate end if end repeat end repeat -- 保存所有修改 save end tell
操作注意事项
- 运行前请先备份整个通讯录数据库,避免误删重要数据:打开通讯录后点击菜单栏「文件」→「导出」→「通讯录归档」即可完成备份
- 如果你不确定自定义标签的准确拼写,可以先运行下方调试脚本,输出所有联系人的日期字段标签,确认匹配文本后再替换正式脚本里的
MyCustomLabel:
tell application "Contacts" set allCustomLabels to {} repeat with eachPerson in people repeat with eachDate in dates of eachPerson set end of allCustomLabels to label of eachDate end repeat end repeat return allCustomLabels end tell
- 脚本运行完成后可以关闭通讯录再重新打开,确认修改已经同步生效
内容的提问来源于stack exchange,提问作者Biagio Distefano
相关产品推荐
相关产品推荐

