0

Is it possible to create a hook so that It clocks in automatically whenever org file is opened for editing Kindly help

1

You could use a file local variable setting like this in your org file:

# Local Variables:
# eval: (org-clock-in)
# End:

This has the benefit of only affecting the files you put it in. If you want it in every file, even new ones, you can make a hook function like this.

(defun my-clock-in ()
  (when (org-before-first-heading-p)
    (org-insert-heading)
    (insert " " (read-string "Heading: ")))
  (org-clock-in))

(add-hook 'org-mode-hook 'my-clock-in)

Note this assumes there is a heading at the beginning of the file, and will add one if not. If that isn't what you want you will have to use a better logic, e.g. to search for an appropriate headline to clock into.

This might not do exactly what you want though, e.g. if you have a set of org buffers open and switch between them, it will not switch the clock between them. There are focus-in-hook and focus-out-hook that might be suitable for that.

  • Thanks. But isn’t it possible to insert first heading * automatically so that the hook runs without error. – Vaibhav Nov 6 at 3:19
  • (add-hook 'org-mode-hook ‘(org-clock-in)) is this syntax ok – Vaibhav Nov 6 at 3:26
  • See the edited solution above for the syntax. – John Kitchin Nov 6 at 13:03
  • Somehow it keeps nagging you for temp saving and then there is no c:*temp* folder. – Vaibhav Nov 7 at 5:40

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.