Site Network: Personal | Professional | Photography

Technical Blog

This blog will contain content related to Java, Seam, Security, my sites and projects, as well as other technical subjects I am interested in.

Comments and questions are welcome!

How to Clean a Corrupt Event From iCal

On rare occasion, iCal under OS X will get really slow, or lock up. In this case the issue was caused by a repeating event which had gotten corrupted somehow and ended up creating over 12,000 instances within the calendar. It looked fine within iCal, however, when you export the calendar, it created a 4.5 MB file, with 12,000+ entries for the event. With that calendar deleted, iCal was fine.

I used TextMate and a regular expression (regex) to delete every instance of the offending event from the exported iCal file.

Step 1: Export each calendar from within iCal to their own .ics files.
Step 2: Quit iCal.
Step 3: Delete the contents from ~/Library/Calendars.
Step 4: Edit the offending .ics file. I used TextMate, but you can use a command line regex tool, BBEdit, Emacs, etc….
Step 5: Use a regex like this:

(?im)BEGIN:VEVENT([^ ]*)(?!END)(Forever)(.*?)END:VEVENT

where “Forever” is the part of the name of the event. It could be any string which only occurs within the bad event. Delete each matching instance. In TextMate I use search-and-replace. Save the file.
Step 6: Start iCal.
Step 7: Import each .ics file.
Step 8: Profit!

8 Responses to “How to Clean a Corrupt Event From iCal”

  1. Jeffrey says:

    This was very helpful. Thanks for posting this. In case it helps someone else (or if I find myself searching for this again), I had to modify it work on my ICS file… Here’s the regex I used in TextMate:

    (^BEGIN:VEVENT$)([^\t]*?)(searchTextHere)([^\t]*?)(^END:VEVENT$)

    Thanks again!

  2. Edward says:

    Hi! I have one of these problems – I looked in the ics file and three birthdays I’d deleted years ago had somehow replicated themselves and made over 7000 entries of themselves. Funny thing is, they don’t appear when the calendar is loaded in iCal. Most of my calendars are less than 50k in size, but this calendar is now 2.8M and I’m not quite that busy a man. Ironically, one of the birthdays is that of an acrimonious ex (talk about continuing annoyance). I’ve tried opening the ics file in TextMate and BBEdit, but neither of the two search regexes seem to work for me – I keep getting a ‘nothing found’, even though I’ve put the whole confounded ‘SUMMARY:Whoever’s Birthday’ into the (SearchTextHere) field. Any suggestions? It’s making my iSync take three hours!

    • Devon says:

      Edward,

      it could be an issue special characters (: or ‘) making the regex unhappy. Can you try with just (Birthday) in there?

      I can take a look, but I’m not sure if you want a stranger looking at your iCal file or not:)

      Devon

      • Edward says:

        Devon,

        I’ve tried with just (Birthday) – doesn’t work for me. Then again, I’m clueless about these things – I’m a Greek & Latin teacher, heh.

        I don’t mind you looking at my ics file at all! How do I get it over to you? Many thanks in advance!

        Edward

  3. Devon says:

    If you have trouble with the regexes on this page, I’ve created a simpler way to clean your iCal files!

    http://digitalsanctuary.com/tech-files/ical-cleaner.php

    You should be able to upload your .ics file, enter one or more unique terms which are only found in the event you wish to be purged, and then hit submit.

    You should get a page back that has a cleaned version of your calendar file. Click “View Source” and copy that into a new .ics file by way of your favorite text editor, such as TextMate. Always keep a backup, as I haven’t tested the online cleaner very thoroughly yet!

  4. Gite says:

    Chiming in a bit late here, but I found that the previous syntaxes either did not work in BBEdit Pro or occasionally selected across duplicate instances of the offending appointment and mistakenly erased legitimate calendar entries.

    The following syntax fixed the problem for me and got rid of 52,000 duplicate calendar entries that were fouling up my MobileMe sync and draining my iPhone’s battery! I’m back to 2 solid days of usage between charges!

    (^BEGIN:VEVENT)([^ ]*)(Name of bad iCal entry)([^ ]*)(^END:VEVENT$)

Leave a Reply