[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: use linux native notifications with tea-time

From: Tassilo Horn
Subject: Re: use linux native notifications with tea-time
Date: Wed, 08 Jun 2011 08:51:34 +0200
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.50 (gnu/linux)

Hi Benjamin,

in case you are using Emacs 24, that comes with notifications.el, which
allows sending off notifications via DBUS.  Just check the function

For my personal use, I've created some wrapper around it that changes
some defaults and allows for dismissing notifications.

--8<---------------cut here---------------start------------->8---
(defun th-plist-put-many (plist &rest args)
  "Put all prop-value pairs given in ARGS into PLIST.

  (th-plist-put-many '(:a 1 :b 2) :a 10 :c 30 :d 40)
  ==> (:a 10 :b 2 :c 30 :d 40)"
  (let ((rest args))
    (while rest
      (setq plist (plist-put plist (car rest) (cadr rest)))
      (setq rest (cddr rest)))

(defvar th-notify-body-to-id-map (make-hash-table :test 'string=)
  "Maps BODY values of notifications to the last notification ID.
If ID is -1, then any further notifications with that body will
be skipped.")

(defun th-notify (&rest args)
  "Create a notification popup.
For ARGS, see `notifications-notify'.
There's some new default behavior over the function above:

  - Notifications with same :body replace each other.  :body,
    because my notifications are usually something like

      :title \"In 15 Minutes\"
      :body \"Meeting with Hugo\"

    where each minute a similar notification with decreasing
    minutes in the :title is triggered.

  - If a notification was dismissed, then don't show any
    notifications with that :body anymore (the next 15 minutes).

  - Use unlimited timeout."
  (require 'notifications)
  (let* ((body (plist-get args :body))
         (replaces-id (or (plist-get args :replaces-id)
                          (gethash body th-notify-body-to-id-map)))
         (on-close (or (plist-get args :on-close)
                       `(lambda (id reason)
                          (when (eq reason 'dismissed)
                            ;; Mark as "don't show again!"
                            (puthash ,body -1 th-notify-body-to-id-map)
                            ;; But clear that "dont-show-mark" after 15 minutes
                            (run-with-timer (* 15 60) nil
                                            (lambda ()
                                              (remhash ,body 
         (timeout (or (plist-get args :timeout)
                      ;; 0 means, it should not expire at all
    (unless (eql replaces-id -1)
      (puthash body (apply 'notifications-notify
                           (th-plist-put-many args
                                              :timeout timeout
                                              :replaces-id replaces-id
                                              :on-close on-close))
--8<---------------cut here---------------end--------------->8---


reply via email to

[Prev in Thread] Current Thread [Next in Thread]