Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 30 lines (26 sloc) 1.1 KB
#!/bin/bash
# sync-calendars, by Nik Reiman, nik.reiman@gmail.com
# Script to sync all events from a google account to your local machine for faster processing
# Path to google command line tool. For more info, see:
# http://code.google.com/p/googlecl/
googleCli="/usr/local/bin/google"
# Names of the calendars you want to fetch
calendars=(Personal Friends "Swedish Holidays" Wrapp)
# Location to store cached calendar files
cacheLocation=$HOME/Library/Caches/Calendars
# You should not have to change anything below this line
today=$(date +"%Y-%m-%d")
nowSeconds=$(date +"%s")
oneDayInSec=86400
numDaysToFetch=30
stopDay=$(date -j -f "%s" "$((${nowSeconds} + ${oneDayInSec} * ${numDaysToFetch}))" +"%Y-%m-%d")
for calendar in "${calendars[@]}" ; do
eval "$googleCli calendar list --cal '$calendar' --date '$today,$stopDay'" > "/tmp/$calendar"
# Do not overwrite calendars if this tool returns non-zero
# TODO: If this tool fails, it barfs all over stderr, which gets consumed by cron. Not so nice.
if [ "$?" -eq "0" ] ; then
mv "/tmp/$calendar" "$cacheLocation/$calendar"
else
rm "/tmp/$calendar"
fi
done