I'm looking into figuring out if it would be possible to display a random quote on the top of my agenda that changes daily or whenever I check out the agenda.

I have a Quotes.org file that I capture to with ** QUOTE items.

Would anything like this be possible?

EDIT: Works with the following code.

(defun read-lines (filePath)
    (insert-file-contents filePath)
    (split-string (buffer-string) "\n" t)))
(setq number-quotes (length (read-lines "~/Documents/emacs/myFile.org")))
(setq org-agenda-custom-commands
      '(("c" "Daily Quote & Agenda & TODOs"
         ((insert (nth (random number-quotes) (read-lines "~/Documents/emacs/myFile.org")))
          (agenda "" nil)
          (alltodo "" nil)

1 Answer 1


You can define a custom agenda command in org-agenda-custom-commands, and add a special function to it. The function should take one argument, a match string (which defaults to the empty string). It can insert whatever text it wants to with insert.

For example, I tried this custom command:

(setq org-agenda-custom-commands
      '(("n" "Agenda and all TODO's"
         ((my-agenda-spook "" nil)
          (agenda "" nil)
          (alltodo "" nil)

And defined my-agenda-spook like this, ignoring the match argument:

(defun my-agenda-spook (&rest _ignore)

Then this appeared at the top of my agenda:

Taiwan Security Council First responder FMS white noise Drug war
analyzer arrangements beanpole bluebird PSAC Afghanistan gorilla ASLET
Basque Separatists

Week-agenda (W42):
Monday     12 October 2015 W42

Global list of TODO items of type: ALL

(spook is an ancient Emacs command that aims to feed NSA's keyword scanner. I just chose it as an example of a function that inserts random strings; you might want to choose a different command for your agenda view.)

  • I cannot seem to make this work. I've tried replacing the spook argument with something very simple like (nth 0 '("one")) but it just doesn't want to work. Am I returning the wrong type of value? Dec 25, 2015 at 15:00
  • 2
    The function needs to insert the string into the buffer, so that should be (insert (nth 0 ...)).
    – legoscia
    Dec 25, 2015 at 15:49
  • Oh man, it works! Thank you! I was tearing my hair out over that one. Dec 26, 2015 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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