Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created October 25, 2018 22:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanv/cfceca96a4d213d14e7329d975a89cdd to your computer and use it in GitHub Desktop.
Save stefanv/cfceca96a4d213d14e7329d975a89cdd to your computer and use it in GitHub Desktop.
#!/bin/bash
# From https://koenig-haunstetten.de/2017/01/02/google-calendar-integration-in-orgmode/
#
# Install into crontab with `crontab -e`:
#
# 3 * * * * ~/scripts/gcal-sync-org > /dev/null 2>&1
#
# Modify your emacs init script to load `diary.google` from DIARY_PATH:
#
# (setq org-agenda-include-diary t)
# (setq diary-file "~/Dropbox/notes/org/diary.google")
DIARY_PATH=~/Dropbox/notes/org
# Add your calendar .ics URLs here (find it in Google Calendar settings)
# Remember to add a backslash after each newline
CALURL=( \
"https://calendar.google.com/calendar/ical/youremail%40domain.com/private-abcdef0123456789/basic.ics" \
"https://calendar.google.com/calendar/ical/otheremail%40otherdomain.com/private-abcdef0123456789/basic.ics" \
"https://calendar.google.com/calendar/ical/mydomain.com_abcdef0123456789loc%40group.calendar.google.com/public/basic.ics"
)
# Because every URL above ends in basic.ics we map those to the real calendar names
# The length of ICSNAME must match the number of URLs in CALURL
ICSNAME=( cal-domain.ics cal-mydomain.ics cal-work-public.ics )
WGET=/usr/bin/wget
OUTDIR=/tmp/calimport
# --- end configuration ---
mkdir -p ${OUTDIR}
cd ${OUTDIR}
rm -f icsdiary.el
# Get the calendar ICS files, and construct an elisp file that
# will import these into my diary.
for ((i=0; i<${#CALURL[@]}; i++)); do
$WGET --no-verbose -O ${ICSNAME[$i]} ${CALURL[$i]};
echo "(icalendar-import-file \"${ICSNAME[$i]}\" \"diary.google\")" >> icsdiary.el
done
rm -f diary.google
emacs --no-init --batch -l icsdiary.el
cp diary.google ${DIARY_PATH}
cd .. && rm -rf ${OUTDIR}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment