I recently turned on Google Sync for the iPhone to enable wireless syncing of my Google calendar and contacts with my iPhone. A limitation of the current version of Google Sync for the iPhone is that it only supports 5 Calendars. I've got more than 5 Calendars in Google Calendar so that's a problem. Fortunately, many of these Calendars are read only (e.g. public/school holidays, your favorite teams game schedule, etc.) and by combining multiple read-only calendars into 1 read-only calendar it is possible to get them all sync-ed between Google Calendar and you're iPhone.

Now all we need is a utility that merges the calendars. Enter merge-ics, a Python script that reads all .ics files in a file system directory and merges them into one new .ics file which you can then import into Google Calendar. Instead of syncing the individual calendars to you iPhone, you now simply sync the combined one. You loose the per calendar color for the merged calendars, but that's acceptable for me.

Of course you can manually download the .ics files of the individual calendars and then import the combined .ics file into Google Calendar, but wouldn't it be nice is this is automated? Do do that I created a shell script that:

  1. downloads individual calendar .ics files. The URLs of these calendars are stored in a text file.
  2. kicks of the merge-ics python script to combine the .ics files

In addition I'm hosting that combined .ics file on my webserver, subscribed to it from Google Calendar and scheduled the script to run on a daily basis. So now I'm able to sync these read only calendars to my iPhone without further manual intervention.

Below are the shell script and an example text file contains the calendars to be merged. If you'd want to use it, make sure you update the variables at the beginning of the script and also update the variables in the merge-ics.py Python script. Needless to say that you'll need to download and install that script form the merge-ics site.

# Script takes one argument: filename containing the URLs of the
# Calendar .ics files to be downloaded.



# Get new copies of the ICAL files
for url in `cat ${ICALSFILE}` ; do

# Only successfuly downloaded files are copied to
# ${TARGET_ICS_DIR} to be able to deal with temporarily
# unavailability of a calendar.
rm -f ${TEMP_ICS_FILE}
wget -q -O ${TEMP_ICS_FILE} ${url}
if [ $? -eq 0 ]; then
cp ${TEMP_ICS_FILE} ${TARGET_ICS_DIR}/`basename ${url}`
echo "Calendar ${url} could not be retrieved"


# Run the merge_ics script

Example text file with input:



  1. how to ollie said...

    Excellent post and writing style. Bookmarked.  

Post a Comment