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!


Posted

in

by

Tags:

Comments

13 responses to “How to Clean a Corrupt Event From iCal”

  1. Jeffrey Avatar
    Jeffrey

    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!

    1. Devon Avatar

      Cool, thank you!

  2. Edward Avatar
    Edward

    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!

    1. Devon Avatar

      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

      1. Edward Avatar
        Edward

        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

        1. Devon Avatar

          Well, Latin stumped me for two semesters so don’t feel badly:) You can e-mail it to me at [email protected] and I’ll take a look.

  3. Devon Avatar

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

    http://172.31.20.105/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 Avatar
    Gite

    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$)

  5. Stephan Avatar
    Stephan

    Hi,

    Sorry for dummy question, but where to use the regex in text mate?? I tried in search and replace, but no go there??? Thanks for help!

    1. Devon Avatar

      Stephan,

      in the find and replace dialog, there is a checkbox on the bottom left for “Regular Expression” which lets you use regex in the find and replace.

  6. liza myers Avatar

    My iCal is corrupted. When I enter a repeating event it shows up multiple times.
    I have read this forum and others and I haven’t a clue how to even start doing what is described in them. I’m not a complete idiot but the processes above might as well be in greek or latin or even chinese for me.
    Do I have to drive 3 hours to an Apple store to fix it? Very frustrating!

  7. Matthew Elvey Avatar

    Well, it’ll be interesting to give this a try with my iCal files in an iCloud world…..

    There’s some sort of madness in my iCal files that needs clearing up; iCal processes are eating up ridiculous amounts of CPU, and my Calendars file went from a large 35MB shortly before going iCloud to a huge 102MB after. (102MB drops to 30MB if I exclude these:
    Calendar Cache*,
    Calendars and Reminders 9.24.12 8.44 AM.icbu
    Calendar Sync Changes

    Still, as someone said, I’m not that popular…

    https://discussions.apple.com/docs/DOC-2095 should probably point here!

    1. Julian Avatar

      We make a free online duplicate remover. The permit file size is 60k, but if you need more, I can give you.
      Link: http://www.config.bg/ics

Leave a Reply

Your email address will not be published. Required fields are marked *

PHP Code Snippets Powered By : XYZScripts.com