Using Emacs - 26 - Google Calendar, Org Agenda


A while ago I did a couple of videos on how I use org-capture (part 1, part 2). I didn't get into a big part of org-capture - how I use org-mode and capture to manage my calendar and todo lists.

I was waiting to see if I liked my current setup - using org-gcal to sync with my Google Calendar for appointments while using my main org file for my todo list.

Coincidentally, Rainer König recently put up a video on how he syncs with his Google calendar. He uses a different method than the one I present in this video so make sure to check out his approach. In fact, you should check out his entire series on org-mode.

Here's the code I use install org-gcal. The video steps through setting up things on the Google side. You'll have to replace the **client ID** and client secrets in the code below as well as use your calendar name and whatever org file you want to sync with.

(setq package-check-signature nil)

(use-package org-gcal
:ensure t
(setq org-gcal-client-id "oauth 2.0 client ID"
org-gcal-client-secret "client secret"
org-gcal-file-alist '(("" .  "~/Dropbox/orgfiles/"))))

I use these two hooks to sync things semi-automatically. The first hook syncs whenever I load the agenda. Since this happens in the background, if I just added something to my calendar, I might have to reload the agenda by hitting r in the agenda view.

The second hook syncs with my Google calendar when I capture.

(add-hook 'org-agenda-mode-hook (lambda () (org-gcal-sync) ))
(add-hook 'org-capture-after-finalize-hook (lambda () (org-gcal-sync) ))
    Here are the rest of my settings. The org files I want to include in my agenda views:
  • -- the one I'm syncing
  • -- my main org file for todo items (the todo capture places
  • things in here)
  • -- my old schedule before I was syncing with
  • Google. Not active anymore. I should probably remove it.

Also, my capture settings:

(setq org-agenda-files (list "~/Dropbox/orgfiles/"

(setq org-capture-templates
'(("a" "Appointment" entry (file  "~/Dropbox/orgfiles/" )
"* %?\n\n%^T\n\n:PROPERTIES:\n\n:END:\n\n")
("l" "Link" entry (file+headline "~/Dropbox/orgfiles/" "Links")
"* %? %^L %^g \n%T" :prepend t)
("b" "Blog idea" entry (file+headline "~/Dropbox/orgfiles/" "Blog Topics:")
"* %?\n%T" :prepend t)
("t" "To Do Item" entry (file+headline "~/Dropbox/orgfiles/" "To Do")
"* TODO %?\n%u" :prepend t)
("n" "Note" entry (file+headline "~/Dropbox/orgfiles/" "Note space")
"* %?\n%u" :prepend t)
("j" "Journal" entry (file+datetree "~/Dropbox/")
"* %?\nEntered on %U\n  %i\n  %a")
("s" "Screencast" entry (file "~/Dropbox/orgfiles/")
"* %?\n%i\n")))

The end result is that I can add an event in my Google calendar (or accept a calendar invite) and it appears in my org-mode agenda. Likewise, I can add a scheduled event using capture and it will sync up to Google. I can also just add an event by editing but then would have to run org-gcal-post-at-point to send it up to Google.

Now, I can use bring up a regular agenda C-a a, my todo list C-a t or by adding a custom agenda command:

(setq org-agenda-custom-commands
'(("c" "Simple agenda view"
((agenda "")
(alltodo "")))))

a combined agenda and todo view using C-a n

Finally, there's calfw. It's a nice tool to view calendars in Google. I don't use it much anymore but it is nice:

(use-package calfw
:ensure ;TODO:
(require 'calfw)
(require 'calfw-org)
(setq cfw:org-overwrite-default-keybinding t)
(require 'calfw-ical)

(defun mycalendar ()
;; (cfw:org-create-source "Green")  ; orgmode source
(cfw:ical-create-source "gcal" "https://somecalnedaraddress" "IndianRed") ; devorah calender
(cfw:ical-create-source "gcal" "https://anothercalendaraddress" "IndianRed") ; google calendar ICS
(setq cfw:org-overwrite-default-keybinding t))

(use-package calfw-gcal
:ensure t
(require 'calfw-gcal))


Better version:

Old, bad version: