3

I am trying to generate nice end-of-day reports in the file diary.org for logging and archiving purposes. I would like to generate a simple list of all TODO task state changes for the current day to be saved to diary.org, but I'm not sure how to get this data there automatically.

I am using org-log-done (see: https://www.gnu.org/software/emacs/manual/html_node/org/Closing-items.html), since I thought it'd help to have timestamps to search for the right data, and I also experimented with org-agenda-log-mode (see: https://orgmode.org/manual/Agenda-commands.html), but was unable to figure out how to export this data (and I would prefer simply exporting the time stamps and headings using org-log-done info anyway, as I already generate a daily clocktable and org-agenda-log-mode will then provide redundant information in a format I like less).

Lastly, I thought this link would help more, but I couldn't extract or assemble any specifically useful info for my case from it: https://orgmode.org/manual/Tracking-TODO-state-changes.html

Thank you in advance for any help.

EDIT: In the mean time, I've developed a temporary work around by simply clocking in and out quickly whenever I change a task state, so that this information can be pulled by org-clock-report. A more elegant solution would probably involve using org-ql (see: https://github.com/alphapapa/org-ql), but I've heard that persistently using logbooks or archiving "DONE" tasks might also achieve what I seek. For now, I like this solution.

1
  • Any updates? Have you found a good way to do this? Feb 12, 2020 at 3:15

1 Answer 1

1

org-ql is now a good solution for this. For example, here's a command that displays recent items, which you could easily adapt:

(cl-defun org-ql-agenda-recent-items (days &optional (type 'ts))
  "Show items from previous DAYS days with timestamps of TYPE.
TYPE may be `ts', `ts-active', `ts-inactive', `clocked',
`closed', `deadline', `planning', or `scheduled'."
  (interactive (list (read-number "Days: ")
                     (->> '(ts ts-active ts-inactive clocked closed deadline planning scheduled)
                          (completing-read "Timestamp type: ")
                          intern)))
  (let ((from (->> (ts-now)
                   (ts-adjust 'day (* -1 days))
                   (ts-apply :hour 0 :minute 0 :second 0)
                   ;; Formatting isn't required, but it looks better in the header than a struct.
                   ts-format)))
    (org-ql-search (org-agenda-files)
      `(,type :from ,from :to ,(ts-format (ts-now)))
      :title "Recent items"
      :sort '(date priority todo)
      :groups '((:todo "DONE")
                (:category "log" :tag "log")
                (:auto-parent t)
                (:auto-todo t)))))

;; Show entries with any timestamp from last 7 days:
(org-ql-agenda-recent-items 7)

;; Show entries clocked in last 7 days:
(org-ql-agenda-recent-items 30 'clocked)

;; Show entries closed in last 7 days:
(org-ql-agenda-recent-items 30 'closed)

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.