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:
Backup calendar(s) to both ICS and ICBU formats; print to PDF for good measure
Recover recalcitrant events from iPhone using iExplorer
Install icalBuddy2 version 1.8.10 via Homebrew3:brew install ical-buddy
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
Combine all 2003–2017 txt files into one:awk 'FNR==1{print ""}1' *.txt > events.txt
Check for duplicates:uniq -d events.txt
and remove:uniq events.txt > events_deduped.txt
Remove auto-generated URLs for events created via iMessage or Mail:sed '/^\ \ \ \ url:/d' events_deduped.txt > events_urls_removed.txt
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)
Namely (and mainly from How To Reset Calendar, iTunes USB Sync):
deleting calendar caches (~/Library/Calendars/Calendar Cache*
and ~/Library/Caches/com.apple.iCal
)
deleting Calendar preference files (~/Library/Preferences/com.apple.iCal.plist
and ~/Library/Preferences/com.apple.iCal.helper.plist
)
resetting iTunes Calendar sync ( (no longer a thing since Mavericks apparently)$ /System/Library/Frameworks/SyncServices.framework/Versions/A/Resources/resetsync.pl full
)
importing events from the phone to the Mac via iExplorer and then overwriting the iPhone's calendar via iTunes
etc.
To avoid a bug in the officially-hosted version (1.8.8) under OS X 10.10+.
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.
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:
iCal: Highlight & delete all events or events within a date range
iCal: Delete all events before or after a certain date via AppleScript
AppleScript to clear the Apple Calendar cache - SolarWinds recently locked FixItScripts behind a paywall for their customers only; a request for access was denied. The referenced script is also sadly missing from Internet Archive's Wayback Machine.
Barney-15E's answer to How to erase all files of the Calendar?
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.
jherran's sed script: events are not returned chronologically (or alphabetically, or in any discernible order)
Tried Calex based on its byline (The Calendar Exporter
), but it only exports to ICS (which Calendar.app does already). Further, it only exported a few hundred events before stopping.
iCalendar archiver "Tool to archive old iCalendar entries into files per year." Python script; ran successfully but resultant ICS file did not differ appreciably from the original.
Archiving via BusyCal: If you're still running Tiger or Leopard, iCal Archiver from the BusyCal team might help.
icsp: "Command-line iCalendar (.ics) to CSV utility. Pure bash, no dependencies."
/mac | Apr 01, 2018