---
deprecated: true
excerpt_separator: <br/>
category: technology
layout: post
title: emacs 23, dbus, and libnotify
date: '2009-08-31T18:47:00.000-04:00'
author: Anna Wiggins
tags:
- emacs
- programming
- Technology
modified_time: '2013-10-22T11:19:50.826-04:00'
blogger_id: tag:blogger.com,1999:blog-4209116010564764361.post-6878792725228849848
blogger_orig_url: http://www.stringofbits.net/2009/08/emacs-23-dbus-and-libnotify.html
---

A new major version of <a href="http://www.gnu.org/software/emacs/">emacs</a> is out, and it includes dbus support.  This is great, because it means we can do things like this:<br/><br/><blockquote><pre><br/>(require 'dbus)<br/>(defun send-desktop-notification (summary body timeout)<br/>  "call notification-daemon method METHOD with ARGS over dbus"<br/>  (dbus-call-method<br/>    :session                        ; use the session (not system) bus<br/>    "org.freedesktop.Notifications" ; service name<br/>    "/org/freedesktop/Notifications"   ; path name<br/>    "org.freedesktop.Notifications" "Notify" ; Method<br/>    "emacs"<br/>    0<br/>    ""<br/>    summary<br/>    body<br/>    '(:array)<br/>    '(:array :signature "{sv}")<br/>    ':int32 timeout))<br/><br/>(defun pw/compile-notify (buffer message)<br/>  (send-desktop-notification "emacs compile" message 0))<br/><br/>(setq compilation-finish-function 'pw/compile-notify)<br/></pre></blockquote><br/><br/>Add this to your .emacs file and you will receive a libnotify popup when M-x compile completes.  It will even give you the exit message, so you know whether the compile was successful.<br/><br/>So now you can let that long compile run, and work on <a href="http://xkcd.com/303/">something else</a>.  emacs will let you know when the compile finishes.<br/><br/>As written above, the notifications will stay on your screen until you dismiss them (by clicking on them).  If you would like them to vanish after a preset time limit, change the 0 in the call to send-desktop-notification.  Set it to the number of milliseconds the popup should remain on the screen.<br/><br/>[caption id="attachment_173" align="alignright" width="300" caption="Screenshot of libnotify popup showing a compiler error"]<a href="http://stringofbits.files.wordpress.com/2009/08/compile_bad1.png"><img src="http://stringofbits.files.wordpress.com/2009/08/compile_bad1.png?w=300" alt="Screenshot of libnotify popup showing a compiler error" title="compile_bad" width="300" height="99" class="size-medium wp-image-173" /></a>[/caption]<br/><br/>This is just the tip of the iceberg, of course.  Any application that presents a dbus interface can be interacted with from emacs, which means that emacs can also integrate itself with the Linux desktop in <a href="http://emacs-fu.blogspot.com/2009/01/using-d-bus-example.html">other interesting ways</a>.