Emacs and org-mode are taking over my life. I've been using emacs for schedule and agenda management for a while and one of the annoyances was getting a quick heads up of today's tasks while on the go. Well.. why not get emacs to make me one?

It turns out that this is trivial. Emacs has a batch mode that allows you to evaluate scripts without starting the editor. You can pass it files to run or emacs lisp commands as string parameters. I have a server with all my dotfiles on it already so I set up a simple cron job on my laptop that simply tells Emacs to export my agenda with the org-batch-agenda command and emails me the output.

It's important to note that in batch mode Emacs won't read any standard configuration files unless you tell it to, so I've passed in the -l ~/.emacs flag to tell it to load my .emacs. This loads my literate config using org-babel-load-file (see here for more information) which importantly contains the following lines:

(require 'cl) ; remove-if-not is inside the common-lisp package
(setq org-agenda-files (remove-if-not 'file-exists-p '("~/Repositories/notes" "~/repositories/notes" "~/Dropbox/life" "~/repositories/life")))

Since I use org on several machines that for an inexplicable reason have different locations for my notes, I tell org to look in whichever of the directories in that list exist. For most people this will be as simple as:

(setq org-agenda-files '("~/notes"))

And that's pretty much it. The cron line pipes the agenda (which is written to the standard output) directly into mail. It looks like this:

# m h  dom mon dow   command
0 6 * * *  /usr/local/bin/emacs --batch -l ~/.emacs  -eval '(org-batch-agenda "a")' 2>/dev/null | mail -s "Martin's Agenda for $(date +'\%A \%D')" martin@mfoot.com

Customising org's agenda mode is simple with features like custom agenda views available. Since I'm not great at lisp I could even have Emacs pipe the agenda through some embedded source block which does some formatting in Python or Ruby and then email that to me.