通过AppleScript删除指定Apple Calendar事件失败的技术求助
搞定AppleScript删除指定日历事件的问题
嘿,看你的描述,你已经能定位到Calendar里的"Test Event",但就是删不掉对吧?你的现有脚本差了关键的删除逻辑,而且看起来没写完(最后卡在calendar "Pri...),我给你整理了完整的可运行脚本,一步到位解决问题:
set theStarttime to date "Wednesday, 18 April 2018 at 17:00:00" set theEndtime to date "Wednesday, 18 April 2018 at 18:00:00" set theSummary to "Test Event" tell application "Calendar" -- 替换成你实际使用的日历名称,比如"Primary"或者"工作" set targetCalendar to calendar "Primary" -- 精准筛选符合条件的事件:标题、开始/结束时间完全匹配 set targetEvents to every event of targetCalendar where (summary is theSummary) and (start date is theStarttime) and (end date is theEndtime) -- 遍历删除所有匹配到的事件(防止有重复事件) repeat with anEvent in targetEvents delete anEvent log "成功删除事件: " & summary of anEvent end repeat -- 强制保存更改,确保Calendar同步删除操作 save end tell
几个要注意的细节:
- 日历名称必须准确:原脚本里的
calendar "Pri...肯定是没写完,比如你的日历叫"Primary"或者"个人",必须和Calendar应用里显示的名称完全一致,不然找不到目标日历,后续操作全白搭。 - 日期格式要适配系统:如果你的Mac系统是中文环境,日期格式得改成
"2018年4月18日 星期三 17:00:00"这种,不然AppleScript会解析失败,找不到对应时间的事件。 - 先测试再删除:怕误删的话,可以先把
delete anEvent改成display dialog "即将删除事件: " & summary of anEvent,先确认找到的是你要删的,再换回删除命令。 - 别忘
save命令:删除后执行save能强制Calendar把更改写入本地数据库,避免删除操作没生效。
内容的提问来源于stack exchange,提问作者Christoffer
相关产品推荐
相关产品推荐

