showing pop-ups






Updated: yes, it's %s, not %d Sometimes, it's nice when emacs can warn you when something is happening or
should happen. For example, when a new e-mail has arrived, or when there's a
meeting in 15 minutes you should attend.



As always, there are different way to do this, but here's what I've been using
for while. Various versions of this have been circulating around mailing
lists, so I don't know whom to credit with the original idea – anyway, this
is the (modified) version that I'm using.





(defun djcb-popup (title msg &optional icon sound)
"Show a popup if we're on X, or echo it otherwise; TITLE is the title
of the message, MSG is the context. Optionally, you can provide an ICON and
a sound to be played"


(interactive)
(when sound (shell-command
(concat "mplayer -really-quiet " sound " 2> /dev/null")))
(if (eq window-system 'x)
(shell-command (concat "notify-send "

(if icon (concat "-i " icon) "")
" '" title "' '" msg "'"))
;; text only version

(message (concat title ": " msg))))






A couple of notes:




  • I'm using notify-send for sending notifications; this assumes you are
    using that system (it's part of the libnotify-bin package in
    Debian/Ubuntu). You can of course replace it with whatever is available on
    your system. Alternatives are zenity or kdialog or xmessage (for
    old-timers) and their equivalents (?) on Windows, MacOS.



  • I'm now using mplayer for playing sounds. This is a bit heavy, but at
    least plays all kinds of audio files. If you only care about .wav-files,
    you could replace it with e.g. aplay;


  • as always, please ignore my ego-centric function names :-)




Now, we can use this function by evaluation e.g.




(djcb-popup "Warning" "The end is near"
"/usr/share/icons/test.png" "/usr/share/sounds/beep.ogg")








showing pop-ups from org-mode appointments






The above popup function is most useful when it's does its work based on some
event. To be notified of appointments and the like, there is the emacs appt facility. Here, we set up this appt, and then hook it up with org-mode, so

appt can warn us when there's something happening soon…





;; the appointment notification facility
(setq
appt-message-warning-time 15 ;; warn 15 min in advance

appt-display-mode-line t ;; show in the modeline
appt-display-format 'window) ;; use our func
(appt-activate 1) ;; active appt (appointment notification)
(display-time) ;; time display is required for this...

;; update appt each time agenda opened

(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)

;; our little façade-function for djcb-popup
(defun djcb-appt-display (min-to-app new-time msg)
(djcb-popup (format "Appointment in %s minute(s)" min-to-app) msg
"/usr/share/icons/gnome/32x32/status/appointment-soon.png"

"/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg"))
(setq appt-disp-window-function (function djcb-appt-display))






Of course, you can freely choose a icon / sound to your liking.







showing pop-ups for new mail






Another event you might want to be warned about is new mail. There is
something to be set for not letting yourself be disturbed for new mail, but
if you sufficiently filter your mails before they enter your inbox, it can be
a good way to periodically bring you back from your deep sl ^H^H thinking. For
Wanderlust, I use something like this:





(add-hook 'wl-biff-notify-hook
(lambda()
(djcb-popup "Wanderlust" "You have new mail!"
"/usr/share/icons/gnome/32x32/status/mail-unread.png"
"/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg")))






Exercise for the reader: adapt this for your chosen mail client.




No comments:

Post a Comment

Followers

Popular Posts