I want to capture a journal entry several times a day. Here was my initial solution:
(setq org-capture-templates '(("w" "Weekly" item
(file+olp+datetree "/home/joe/org-files/goodtime.org")
"%?" :tree-type week)))
(mapc
(lambda (slot)
(run-at-time slot
(* 60 60 24) ; repeat each day at the same time if Emacs is still running
(lambda ()
(interactive)
(org-capture nil "w")
(insert (format-time-string "%-H:%M " nil t)))))
'("09:00am" "12:00pm" "3:00pm" "6:00pm" "9:00pm"))
This seems to work as expected if I start Emacs before 9AM.
However, if I start Emacs later than that, the Org Capture runs immediately, once for each time of day that has been missed. I see now that this is explained in the answer here: Is it possible to execute a function or command at a specific time?
The problem is that I want to run the task exactly at the times mentioned, not potentially at some other time.
Thinking out loud, one solution would be to write in an explicit conditional that takes note of the time when Emacs starts, checks whether that was within the last 24 hours, and runs the capture event or not as required. This seems pretty heavy for a one-off solution, and I wonder if actually run-at-time
should be patched?
Before trying to do this with run-at-time
I tried to use emacsclient
inside of a cron
job, but that didn't work for me. The script runs on its own, but I wasn't able to get it to work from within cron
, which apparently doesn't play nicely with interactive "desktop" jobs.