Archiving Calendar.app events as plain text #

After 14 years of calendar events (>17,000, but still well within the recommended limit of 50,000), Calendar.app finally started acting up; a month-long period refused to sync via iTunes from an iPhone to a Mac, despite desultory remedial efforts1.

Time to archive and cleanup:

  1. Backup calendar(s) to both ICS and ICBU formats; print to PDF for good measure

  2. Recover recalcitrant events from iPhone using iExplorer

  3. Install icalBuddy2 version 1.8.10 via Homebrew3:
    brew install ical-buddy

  4. Export all events from 2003 through 2017 using a for loop4:
    for i in {2003..2017}; do icalBuddy --separateByDate --noCalendarNames eventsFrom:$i-01-01 to:$i-12-31 > $i.txt; done

  5. Combine all 2003–2017 txt files into one:
    awk 'FNR==1{print ""}1' *.txt > events.txt

  6. Check for duplicates:
    uniq -d events.txt
    and remove:
    uniq events.txt > events_deduped.txt

  7. Remove auto-generated URLs for events created via iMessage or Mail:
    sed '/^\ \ \ \ url:/d' events_deduped.txt > events_urls_removed.txt

  8. Delete 2003–2017 events from Calendar via Automator5: Find Calendar Events > Date ending > is before > 1/1/2018 > Delete Calendar Events6 (UPDATE: See macOS: Batch delete calendar events via Shortcuts.app)

Footnotes

  1. Namely (and mainly from How To Reset Calendar, iTunes USB Sync):

  2. Export iCal events to TXT or RTF

  3. To avoid a bug in the officially-hosted version (1.8.8) under OS X 10.10+.

  4. Exporting all events from 2003 through 2017 like so: $ icalBuddy --separateByDate --noCalendarNames eventsFrom:'jan 1, 2003' to:'december 31, 2017' completed without error, but stopped in 2006, hence the for loop.

  5. Calendar, Automator, and AppleScript were so recalcitrant under macOS Sierra that an OS X Mountain Lion virtual machine had to be employed for the cleanup process. More on deleting old events:

  6. Under macOS 10.14 Mojave, had to grant Full Disk Access to Automator (to prevent "The calendar is read only" error) and change the workflow slightly: Get Specified Calendar Items > Add > select calendar > Filter Calendar Items > Filter > events > Date ending > is before > 1/1/2019 > Delete Calendar Events > "If events are recurring, delete" > these events only.

Failed attempts

Related

Update

/mac | Apr 01, 2018


Subscribe or visit the archives.