0

Is there an org-mode hook that would allow me to run a custom function after scheduling an entry (i.e. running C-c C-s/org-schedule in an Org buffer)? I've checked https://orgmode.org/worg/doc.html, but I don't see anything that will help. I tried to see if org-property-changed-functions would work like this:

(add-hook 'org-property-changed-functions
          (lambda (name value)
            (message "%s %s" name value)))

It works for properties like "Effort", but not for things like "SCHEDULED".

Is there any other way I can achieve this? I'm using Emacs version 27.2 on macOS with Org mode version 9.4.4.

1 Answer 1

1

There is no such hook (org-property-changed-functions does not apply to Special Properties unfortunately), but the other standard method to customize the behavior of a function is to advise it and that does apply here. If the custom function that you want to apply is always the same, then the simplest thing to do is to call that function at the end of org-schedule. Assuming that your custom function is called my/custom-function, and it takes the same arguments as org-schedule (which you can always disregard if you want), you can add this to your init file:

(advice-add 'org-schedule :after #'my/custom-function)

If there are problems, you can remove the advice with

(advice-remove 'org-schedule #'my/custom-function)

and try again.

I tested with a stupid custom function:

(defun my/custom-func (arg &optional time)
  (message "my/custom-func was called"))

and it seems work (for some value of "work").

Advising a function can get complicated fairly fast, but for simple modifications, the above will suffice.

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.