Skip to main content

C'est la Z

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
:config
(setq org-gcal-client-id "oauth 2.0 client ID"
org-gcal-client-secret "client secret"
org-gcal-file-alist '(("zamansky@gmail.com" .  "~/Dropbox/orgfiles/gcal.org"))))

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:

  • gcal.org – the one I'm syncing
  • i.org – my main org file for todo items (the todo capture places

things in here)

  • schedule.org – 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/gcal.org"
"~/Dropbox/orgfiles/i.org"
"~/Dropbox/orgfiles/schedule.org"))


(setq org-capture-templates
'(("a" "Appointment" entry (file  "~/Dropbox/orgfiles/gcal.org" )
"* %?\n\n%^T\n\n:PROPERTIES:\n\n:END:\n\n")
("l" "Link" entry (file+headline "~/Dropbox/orgfiles/links.org" "Links")
"* %? %^L %^g \n%T" :prepend t)
("b" "Blog idea" entry (file+headline "~/Dropbox/orgfiles/i.org" "Blog Topics:")
"* %?\n%T" :prepend t)
("t" "To Do Item" entry (file+headline "~/Dropbox/orgfiles/i.org" "To Do")
"* TODO %?\n%u" :prepend t)
("n" "Note" entry (file+headline "~/Dropbox/orgfiles/i.org" "Note space")
"* %?\n%u" :prepend t)
("j" "Journal" entry (file+datetree "~/Dropbox/journal.org")
"* %?\nEntered on %U\n  %i\n  %a")
("s" "Screencast" entry (file "~/Dropbox/orgfiles/screencastnotes.org")
"* %?\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 gcal.org 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:
:config
(require 'calfw)
(require 'calfw-org)
(setq cfw:org-overwrite-default-keybinding t)
(require 'calfw-ical)

(defun mycalendar ()
(interactive)
(cfw:open-calendar-buffer
:contents-sources
(list
;; (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
:config
(require 'calfw-gcal))

Enjoy.

Better version:

Old, bad version:

Relevant links:

comments powered by Disqus