1

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.

  • 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 May 11 '17 at 20:23
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)
  • What is treport/org-main-file? – NickD May 14 '17 at 20:43
  • @Nick, this is my main and only org file with tasks. (answer updated) – Valeriy May 14 '17 at 21:13
  • OK - I see: the "treport/" was a typo. – NickD May 15 '17 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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