Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Remove old events from Calendar Apps
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."
        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
  • Currently 2.14 / 5
  You rated: 4 / 5 (7 votes cast)

Remove old events from Calendar | 4 comments | Create New Account
Click here to return to the 'Remove old events from Calendar' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Remove old events from Calendar
Authored by: karog on Sep 23, '13 08:15:17AM
This line
if the number of items in r > 1 then
should be
if the number of items in r < 1 then
Note the test was backward.

[ Reply to This | # ]
Remove old events from Calendar
Authored by: guillaumegete on Sep 23, '13 08:37:18AM

There's an even easier method : the Automator way.

Use the following actions :

- Get Specified Calendar items
- Find Calendar events (and adapt this one to your needs)
- Delete Calendar items.

Presto !

No rule, no future, no comment, no signature.

[ Reply to This | # ]
Remove old events from Calendar
Authored by: Supp0rtLinux on Sep 23, '13 01:13:53PM

With some extra shelling scripting to use the 'date +%' options to determine the current day, you could have this setup to always remove everything but the last x number of days. So… you could use 'date +%' and then set it to remove everything 60 or 90 or 180 days older and only keep the last 2 months, 3 months, or 6 months of events. You could then also have it run in launchd or cron or a tool like Do Something When to run once a day and never touch it again...

[ Reply to This | # ]
Remove old events from Calendar
Authored by: chrischram on Sep 25, '13 11:30:08AM

I've been using the Automator approach for awhile now. It works well, and of course is less prone to potentially data-killing coding errors.

[ Reply to This | # ]