4

I read my email in Emacs, and every now and then I receive an ICS file as an attachment, usually in a confirmation message for an event I've signed up for. That's very kind of them, because it means I don't need to enter the event into my calendar manually. It looks like this in the message buffer:

Attachment: [4. text/calendar; foobar.ics]...

I want to import that event into Google Calendar. Currently I handle those files like this:

  • Save the ICS attachment from within message-mode (move point to the attachment and hit o)
  • Open Google Calendar in my web browser
  • Click the cogwheel, and select "Settings" in the menu that appears
  • Open the "Calendars" tab in the settings page
  • Click the "Import calendar" link
  • Select the ICS file in the file upload input control
  • Select which calendar to add the event to
  • Click the "Import" button

It gets tedious after a while. How can I import the event into Google Calendar directly from Emacs, without all these intermediate steps?

  • 2
    There's a command line interface to Google calendar which you​could use. It's not very efficient but for small calendar files it should be enough. Then you'll have to wrap this in an Emacs command. I hope someone will do that. – YoungFrog Apr 12 '17 at 20:51
  • @YoungFrog Good idea. It wasn't very hard :) – legoscia Apr 14 '17 at 22:04
4

There is a command line interface to Google Calendar called gcalcli. You can install it using pip:

pip install gcalcli

In order to import calendar files, gcalcli requires the vobject library to be installed:

pip install vobject

The first time you run gcalcli, it will launch a web browser in order to obtain an oauth token, which it will save in ~/.gcalcli_oauth. list is a good command to use:

gcalcli list

Now that gcalcli is installed, let's configure Emacs to use it. Add the following entry to your ~/.mailcap file (create it if it doesn't exist):

text/calendar; /path/to/gcalcli --calendar 'Calendar Name' import %s

"Calendar Name" is the name of the calendar you want to import calendar entries into, as listed by gcalcli list.

To make Emacs pick up the new entry, type M-x mailcap-parse-mailcaps.

To import a calendar file, move point to the [4. text/calendar; foobar.ics] part, hit ., and enter view externally as the "action". Emacs will run gcalcli and display the output in the message buffer — hopefully New event added: https://.....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.