Skip to main content
5 of 5
added 4 characters in body
Mathieu Marques
  • 2.1k
  • 2
  • 15
  • 31

How to automatically adjust an Org task state with its children checkboxes

I have several tasks in my Org file, one of which has items starting with a checkbox (but only those). They all have a statistic cookie at their end ([n/m]).

I'm looking for a way to automatically update the parent task from TODO to DONE once all of the checkboxes are marked as done as well.

The documentation says:

If you would like a TODO entry to automatically change to DONE when all children are done, you can use the following setup [...]

Another possibility is the use of checkboxes to identify (a hierarchy of) a large number of subtasks (see Checkboxes).

The way I understand that last part is that if children items are checkboxes, parent state should already be automatically updated (which is not the case).

What am I missing?


Edit:

From org-after-todo-statistics-hook's documentation (org.el):

Hook that is called after a TODO statistics cookie has been updated. Each function is called with two arguments: the number of not-done entries and the number of done entries.

Which means that the proposed code from orgmode.org:

(defun org-summary-todo (n-done n-not-done)
  "Switch entry to DONE when all subentries are done, to TODO otherwise."
  (let (org-log-done org-log-states)   ; turn off logging
    (org-todo (if (= n-not-done 0) "DONE" "TODO"))))

(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)

won't count checkbox items.

Mathieu Marques
  • 2.1k
  • 2
  • 15
  • 31