I'm trying to write a script that switches focus to Emacs. This is what I have:
#!/bin/bash
wmctrl -a 'emacs@pat-ubuntu-desktop'
It works fine when there is only one Emacs window (or "frame," in Emacs parlance) open, but it doesn't do anything when multiple Emacs windows are open. The problem seems to be that the window titles change when a second window is opened. When there's a single window open, its name is emacs@pat-ubuntu-desktop
:
➜ ~ wmctrl -l
0x05c000a3 0 pat-ubuntu-desktop emacs@pat-ubuntu-desktop
But when I open a second window, the window titles change:
➜ ~ wmctrl -l
0x05c000a3 0 pat-ubuntu-desktop *scratch*
0x05c00921 0 pat-ubuntu-desktop *scratch*
EDIT: The following issue was illusory, the result of my web browser having "emacs" in its title (because I was searching information about my first problem).
Another issue (perhaps related, perhaps not), is that even when there is only a single Emacs window open, the command wmctrl -a 'emacs'
doesn't work, but wmctrl -a 'emacs@'
(or wmctrl -a 'emacs@pat-ubuntu-desktop'
) does. Why must the @
be included?
frame-title-format
in your.emacs
), andwmctrl -a emacs
works in all cases for me@
symbol was that I was searching in my web browser for information about my first problem, and the title of the web-browser window naturally contained "emacs." Focus was shifted to the web browser, but I didn't even notice, probably because it already had focus. Silly me!(setq frame-title-format '("" invocation-name " %f"))
to my.emacs
solved my problem. Thanks! @MichaelMrozek: Are you using Ubuntu with Unity? Perhaps the inconsistent window names have something to the OS I'm using.