2

I am trying to create an org-capture template for a grocery list, but there seems to be no easy way to get the result I want, and I'm pretty bad at programming. So I was hoping that maybe someone has a solution.

I would like to have a template that does the following: I have a grocery.org file, that should have roughly the following structure:

* <Todays Date> 
- [ ] item 1 
- [ ] item 2

The template should check if there already is a headline with the current date. If so, just add an item to the list. If not, create the headline with the current date and start the list. I tried a couple of things with the standard tools of org-capture, like (file+headline) and (checkitem) and so on, but I really cant get that done.

I really hope someone can offer some help, thanks in advance.

2 Answers 2

2

If you're willing to have things filed as

* <year>
** <month>
*** <day>

then using the file+datetree capture target instead of file+headline will work. It files to the current date, creating it if it doesn't exist.

1
  • I already tried that, but I would like the headline to be an active timestamp so that it shows up in my agenda. file+datetree seems to produce only normal headlines.
    – Florian
    Jul 20, 2016 at 7:07
1

To make the headline active in your agenda, you should add an active date to it. You can add a hook to org-capture to add a date.

(setq org-capture-templates
      '(("g" "Grocery today" checkitem (file+datetree "~/org/grocery.org")
         "[ ] %?")))

(defun schedule-grocery-hook ()
  (if (string= (org-capture-get :description)
               "Grocery today")     ;Must match the description in the template
      (org-schedule 0 (format-time-string "%Y-%m-%d"))))

(add-hook 'org-capture-before-finalize-hook 'schedule-grocery-hook)

This is what I get in grocery.org:

* 2017
** 2017-04 April
*** 2017-04-16 Sunday
    SCHEDULED: <2017-04-16 Sun>
    - [ ] abc

Besides, org-datetree-add-timestamp may be of your interest. But it will add timestamps to all datetree headlines.

Your Answer

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

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