3

I'm trying to write an AppleScript that clears a calendar (an iCloud one) of all of its events. I have the following:

tell application "Calendar"
    tell calendar "Test calendar"
        set the_events to every event
        repeat with current_event in the_events
            delete current_event
        end repeat
    end tell
end tell

In the Script Debugger, I can see that the number of events in the list the_events is going down as it deletes each one. If I run the script again, Script Debugger tells me that there are now no events in the calendar. However I can still access and change the events in the Calendar app, be that on the same computer or on another device or the iCloud website.

What's going on here?

  • I tried using a where clause to select for all but one event in the calendar so that not every event was deleted but the result is the same. – Patrick Apr 20 at 6:31
  • Not sure what the proper protocol is for this reply. It turns out that the calendar needs a refresh to update. Following a comment in a separate post by @CJK, you can ask to "Get info" on any calendar and the deleted events will disappear. I'm still getting use to how programming keystrokes works so what I did was close and open the application using: tell application "Calendar" quit delay 5 activate end tell – Patrick Apr 22 at 3:57

You must log in to answer this question.

Browse other questions tagged .