tags:

views:

204

answers:

3

Hi All,

I'd like to save the output of org-agenda to a text file, every time that the org-agenda is calculated. This way, I can use an external program (like ATNotes on windows or conky on linux), to pick up this text file and display it on my desktop.

How can I do this?

+1  A: 

If you want to do it while you have emacs open, you can just call save-buffer on the *Agenda* buffer via M-x save-buffer (since orgmode binds C-x C-s to org-save-all-org-buffer. You could bind save-buffer to something else in the org-mode-map if you wanted.

If you want to do it via a cron, you should be able to use the snippet in this thread on the org-mode mailing list to pipe the output to a file. I've used this in the past:

    emacs -batch -eval '(org-batch-agenda "a" org-agenda-ndays 7 org-agenda-include-diary nil org-agenda-files (quote ("~/org/todo.org")))' > agenda.txt
seth
I don't want to be saving the buffer to a file each time I change something and re-calculate the agenda, and I'm looking for an entirely emacs based solution.I was thinking along the lines of having to hook to function which calculates the agenda, or maybe using defadvice. Unfortunately, I don't know enough emacs lisp to try anything on my own.
vedang
A: 

So I finally decided to open the emacs lisp manual and figure this out myself. I wrote this bit of code, which seems to be working just fine! :)

;; Save the org-agenda for display with conky
(defadvice org-todo-list (after saveorgagenda activate)
  "save this output to my todo file"
  (get-buffer-create "todo")
  (with-current-buffer "todo"
    (set-buffer-modified-p nil))
  (kill-buffer "todo")
  (write-file "~/todo"))

EDIT REASONS:

1) Without kill-buffer, the defadvice creates a new todo buffer on every execution of org-todo-list. This gets pretty irritating.

2) Without the get-buffer-create function, kill-buffers fails the first time since there is no buffer named todo at that time.

3) Without set-buffer-modified-p, the function will keep telling you "todo buffer is modified. Really kill it? (y or n)" which would defeat the whole purpose really.

Whew! I'm so happy I actually took the time and effort to figure this out! :D

vedang
+1  A: 

I feel like I'm raining on your parade after you went to the trouble to write this code snipped (and used a piece of around advice, too!), but actually this feature is already baked into org-mode, and documented in the manual. The command you want is org-write-agenda (C-x C-w in an agenda buffer). See the section of the org-mode info entitled "Exporting Agenda Views."

Robert P. Goldman
thanks. I wrote something similar some time back (a modification over the code written below), but this is better.
vedang