2009-11-19

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.

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…

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:

19 comments:

this is cool. I created a tool for doing OSD (with the purpose of showing keystrokes such as emacs during presentations or screencasts) [0]. Now I'm wondering if it would be worthwhile/possible to use notify to do this within emacs itself.

This sounds really cool. However, it doesn't seem to work for me. I have libnotify installed (ubuntu 9.10) and the latest emacs-snap-shot version. I do manage to see te notification via the elisp interpreter, but not when new email arrives... Do you perhaps have an idea what may be wrong?

So if I'm getting this right, in order to work, you have to run the agenda command? Is there a way to add the hook so that it runs after you insert the date (either after C-c . or inserting a deadline)? I don't always run the agenda command.

The other thing is that when I tried this it kept bugging me with popups until I marked the task complete. Is there a way to make it popup once?

I think I may have answered my own question. While there doesn't seem to be another good hook to run org-agenda-to-appt, I did find "run-at-time". The following runs org-agenda-to-appt every hour:

(run-at-time "08:01" 3600 'org-agenda-to-appt)

As for the other question, I think "appt-display-interval" controls the number of popups before the deadline.

I'm not always at my computer, so if I'm not physically present at the computer before the deadline, I'll miss the popups altogether. Is there a way for emacs to keep sending you popups until you mark the task as done? Notifications stop coming up after the deadline time even if you still haven't marked them done.

Unfortunately, after playing around with this all day, it seems that emacs' appt system is limited. If you have two appointments at the same time, you get a notification only for one of them. Also, suppose you have two appointments, say at 12pm and 12:10pm. If the appt warning time is 15 minutes, you get warnings only for the 12pm appointment.

The bottom line is that appt is still useful but you'll still need to check your agenda. Don't rely on the appt warnings.

As @HelloWorld said, some emacs users have reported that appt only works for one element when there are many schedules at the same time. So I post my org-appt hack which merges the schedules at same time together: