Remove old events from Calendar

Sep 23, '13 07:30:00AM

Contributed by: pianojoe

Ever wanted to remove all events prior to a given date from your calendar? Well, there's a script for that. This Applescript prompts you for a pivot date and removes all events prior to this date from your Calendar database.

display dialog "Please set the pivot date. (Events earlier than the pivot date will be deleted.)" default answer "01-01-2010" with icon note
set dateLimit to (date the (text returned of the result))
display dialog "This might take a few minutes." giving up after 2

tell application "Calendar"
    set cals to every calendar whose writable is true
    set r to {}
    repeat with c in cals
        set event_list to every event in c
        repeat with e in event_list
            if start date of e is less than dateLimit then
                set r to r & {e} 
            end if
        end repeat
    end repeat
    if the number of items in r > 1 then
		display dialog "Nothing to delete."
    else
        display dialog "Done. Found " & (number of items in r) & " events with a date before " & dateLimit & ". Shall I delete them?"
        repeat with e in r
            delete e
        end repeat
        display dialog "Done." buttons {"OK"} default button 1
    end if

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20130916075137213