Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving the org-agenda

Tags:

emacs

org-mode

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?

like image 841
vedang Avatar asked Aug 09 '09 14:08

vedang


3 Answers

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."

like image 129
Robert P. Goldman Avatar answered Nov 07 '22 13:11

Robert P. Goldman


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
like image 37
seth Avatar answered Nov 07 '22 11:11

seth


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

like image 35
vedang Avatar answered Nov 07 '22 12:11

vedang