There is an
org-clock-out-hook that you can attach a function to:
(defun my-org-clock-out ()
(add-hook 'org-clock-out-hook #'my-org-clock-out)
Unfortunately, there is no variable like
org-clock-duration-last-clock so the above won't work. After having a quick look, I found no plausible candidate for such a variable, nor an easy way to calculate it. So I modified
org-clock.el :-) Here's the diff, if you decide to go this way, but as usual, having your own modifications is fraught with peril:
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index a6eb49e1c..d1a2a4962 100644
@@ -1185,6 +1185,7 @@ so long."
(defvar org-clock-current-task nil "Task currently clocked in.")
(defvar org-clock-out-time nil) ; store the time of the last clock-out
+(defvar org-clock-duration-last-clock nil) ; store the duration of the last clock
@@ -1600,7 +1601,8 @@ to, overriding the existing value of `org-clock-out-switch-to-state'."
h (floor s 3600)
m (floor (mod s 3600) 60))
- (insert " => " (format "%2d:%02d" h m))
+ (setq org-clock-duration-last-clock (format "%2d:%02d" h m))
+ (insert " => " org-clock-duration-last-clock)
(move-marker org-clock-marker nil)
(move-marker org-clock-hd-marker nil)
;; Possibly remove zero time clocks. However, do not add
It adds a global variable
org-clock-duration-last-clock and sets it to the string "HH:MM" that is inserted in the CLOCK line in the drawer. That can then be used by the hook function as described above.
I don't know if there is demand for this feature, but you might want to suggest it as an enhancement on the Org mode mailing list. Who knows? Somebody there (or perhaps here) might have a better way of doing it, without having to make modifications to Org mode.