Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(I'm actually asking this even though I intend to supply the answer, so this is more by way of providing a tip.)

If you create an emacsclient launcher by copying a .desktop file (e.g. the Emacs one), it does not behave in the standard Unity launcher manner. It always launches a new window; it doesn't recognize that existing Emacsclient windows exist to jump to them. How can I make it behave?

As background, this is a very useful usage mode for Emacs, where you run it as a daemon: emacs --daemon, and then you summon an emacs window with emacsclient. A good way to do this for habitual emacs users is to put emacs --daemon into your Startup Applications.

share|improve this question

The solution is to create an emacsclient.desktop file including a directive to it the class of the window using the StartupWMClass settings. Without it, Unity can't tell that that window came from Emacsclient. This will create one based on the contents of the Emacs one (/usr/share/applications/emacs23.desktop):

mkdir -p ~/.local/share/applications
cat > !$/emacsclient.desktop <<EOF
[Desktop Entry]
GenericName=Text Editor
Comment=View and edit files
Exec=/usr/bin/emacsclient -c %F

Place the emacsclient in the launcher (e.g. tap Super, type "emacsclient", drag it on), and log out/in.

share|improve this answer
In my .bashrc, I define TMPDIR=${HOME}/tmp so temporary files are under my encrypted $HOME. emacs, invoked from the launcher, doesn't see this definition, but emacsclient, invoked from a shell does. emacs (after server-start) opens a socket in /tmp, emacsclient tries to communicate with emacs over a socket in ${HOME}/tmp, and does very poorly. Can I use emacsclient.desktop to pass the right value for TMPDIR? – waltinator Sep 28 '11 at 19:40
I moved my question to a thread of its own, and got answered. See… – waltinator Nov 6 '11 at 23:20
Unity totally ignored my emacsclient.desktop for some reason. I eventually got around this by creating the launcher in alacarte (the "Main Menu" GUI) instead. – Brian Z Mar 7 '15 at 9:50

Another way is to use a script:

if [ "$(pidof emacs)" ] ; then
    emacsclient "$@" &
    emacs -mm "$@" &

So you always invoke the same command.

share|improve this answer

Solution by james.ferguson works well. What I wanted was to link emacsclient to so some file types as the "preferred application". For this, I found james's script with a new "Exec" line

Exec=/usr/bin/emacsclient --alternate-editor emacs24 --no-wait %F

works better for me: it runs a new emacs if none is running, does not open a new window and does not make emacs complain about clients still waiting for stuff to happen.

Now I can click on files and they are opened in a running emacs, if one exists, otherwise emacs starts.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.