我正在尝试通过Applescript删除Apple内置日历应用中的特定日历事件。我能够找到事件,但无法使用我找到的方法删除它。
以下脚本定位名为Test Event
的事件,并在日历应用中显示该事件。它工作正常。
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" to tell calendar "Privat"
set theEventList to every event where its start date is greater than or equal to theStarttime
and end date is less than or equal to theEndtime and summary is equal to theSummary
set theEvent to first item of theEventList
show theEvent
end tell
如果我尝试删除该事件而不是通过将行show theEvent
更改为delete theEvent
来显示该事件,则在执行脚本后该事件仍在日历应用中。但是,它似乎以某种方式被删除,因为脚本无法再找到该事件。
如何从日历中删除活动?
答案 0 :(得分:0)
delete
是正确的,但您必须save
日历。我添加了if
条件,如果找不到该事件,则会避免错误。
tell application "Calendar"
tell calendar "Privat"
set theEventList to every event where its start date ≥ theStarttime and end date ≤ theEndtime and summary is equal to theSummary
if theEventList is not {} then
set theEvent to first item of theEventList
delete theEvent
end if
end tell
save
end tell