Skip to content

Instantly share code, notes, and snippets.

@JeffCarpenter
Last active February 3, 2023 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JeffCarpenter/b3925d3b4fb0767c4d43bc9f61f25a69 to your computer and use it in GitHub Desktop.
Save JeffCarpenter/b3925d3b4fb0767c4d43bc9f61f25a69 to your computer and use it in GitHub Desktop.
;; To run export from Bash:
;; emacs -batch -l ~/.emacs.d/init.el -eval "(org-agenda-export-to-ics)" -kill
;; if [[ "$?" != 0 ]]; then
;; notify-send -u critical "exporting org agenda failed"
;; fi
(setq org-directory "~/Dropbox/org/")
(defun set-org-agenda-files ()
"Set different org-files to be used in `org-agenda`."
(setq org-agenda-files (list (concat org-directory "things.org")
(concat org-directory "reference.org")
(concat org-directory "media.org")
(concat org-directory "shared_with/bob.org")
"~/src/your_company/admin/things.org"
"~/src/your_customer/admin/pm.org")))
;; Setting variables for the ics file path
(setq org-agenda-private-local-path "/tmp/dummy.ics")
(setq org-agenda-private-remote-path "/sshx:user@host:path/dummy.ics")
;; Define a custom command to save the org agenda to a file
(setq org-agenda-custom-commands
`(("X" agenda "" nil ,(list org-agenda-private-local-path))))
(defun org-agenda-export-to-ics ()
(set-org-agenda-files)
;; Run all custom agenda commands that have a file argument.
(org-batch-store-agenda-views)
;; Org mode correctly exports TODO keywords as VTODO events in ICS.
;; However, some proprietary calendars do not really work with
;; standards (looking at you Google), so VTODO is ignored and only
;; VEVENT is read.
(with-current-buffer (find-file-noselect org-agenda-private-local-path)
(goto-char (point-min))
(while (re-search-forward "VTODO" nil t)
(replace-match "VEVENT"))
(save-buffer))
;; Copy the ICS file to a remote server (Tramp paths work).
(copy-file org-agenda-private-local-path org-agenda-private-remote-path t))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment