2

How to clock-out current org-task before exit from Emacs? I tried

(add-hook 'kill-emacs-hook #'org-clock-out)

But if there is no current active tasks, Emacs says "No active clock" instead of exit. If there is an active task, in reality clock-out does not occur and the next time when I'm trying to make org-clock-in, see the proposal to resolve the conflict.

1
  • At least for the first part you can say (add-hook 'kill-emacs-hook (lambda () (org-clock-out nil t))). See the doc string for org-clock-out for the meaning of the parameters. I don't know why it does not clock out on exit though: you might want to edebug it and see if it does get called when you kill emacs.
    – NickD
    Commented May 11, 2017 at 20:23

1 Answer 1

2

Solution:

(setq org-main-file "~/orgmode/main.org")
(defun valeriy/exit ()
        (with-current-buffer (find-file-noselect org-main-file)
          (save-excursion
            (org-clock-out nil t)
            (save-buffer))))
(add-hook 'kill-emacs-hook #'valeriy/exit)
3
  • What is treport/org-main-file?
    – NickD
    Commented May 14, 2017 at 20:43
  • @Nick, this is my main and only org file with tasks. (answer updated)
    – Valeriy
    Commented May 14, 2017 at 21:13
  • OK - I see: the "treport/" was a typo.
    – NickD
    Commented May 15, 2017 at 11:57

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.