Assuming you have the current version of org-alert
, I think the best way to do it is to redefine the org-alert--dispatch
function so that the title is dynamically generated by calling a function to calculate it, instead of using the value of a variable:
(defvar org-alert-notification-title-function nil)
(defun org-alert-notification-title ()
"If `org-alert-notification-title-function' is defined and is a function, call it
and return what it returns; otherwise return the value of the variable `org-alert-notification-title'"
(cond ((null org-alert-notification-title-function) org-alert-notification-title)
((not (functionp org-alert-notification-title-function)) org-alert-notification-title)
(t (funcall org-alert-notification-title-function))))
(defun org-alert--dispatch ()
(let* ((entry (org-alert--parse-entry))
(head (car entry))
(time (cadr entry)))
(when (org-alert--check-time time)
(alert (concat time ": " head) :title (org-alert-notification-title)))))
All of these would be changes to org-alert.el
(IOW, you are forking org-alert.el
: if this works for you, I might submit the changes as a PR to the github site): the first two definitions are additions to the file, but the third is a replacement
The above does not change the current behavior: it redefines org-alert--dispatch
to call a function org-alert-notification-title
(instead of using the variable of the same name directly - btw, emacs lisp allows the same name to be used for a variable and a function: if the name appears in a function context, the function value is used, otherwise the variable value is used).
When that function is called, it checks a (new) variable org-alert-notification-title-function
: if that variable is nil or is not a function, then the value of the variable org-alert-notification-title
is returned, which reproduces the current behavior. But if you redefine org-alert-notification-title-function
to have a function that returns a string as its value, the function is called and the returned string is the return value of the call to the org-notification-title
function. The point is that the function is called when the notification is needed, so it can take advantage of its context to return information of interest (like the file name of the buffer in which it is evaluated: it just so happens that it is evaluated in exactly the buffer of the file that contains the entry that gives rise to the notification - phew!)
So you can customize the behavior by defining your own function and setting it as the value of the variable org-alert-notification-title-function
in your init file:
(defun ndk/org-alert-notification-title ()
(concat "*ORG* " (let ((fn (buffer-file-name))) (if fn (file-name-base fn) "no file?"))))
(setq org-alert-notification-title-function #'ndk/org-alert-notification-title)
BTW, there is a bug in org-alert.el
: it only recognizes DEADLINE
or SCHEDULED
timestamps - it does not recognize plain timestamps. See this Important note in the manual for why this is a serious omission.
In addition, org-alert
's error handling is not particularly robust: if org-alert--parse-entry
does not recognize a time, then a nil
is passed to org-alert-check--time
and the latter keels over and dies.
defvar
): it needs to be done dynamically, i.e. when the notification is generated.