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
➜ ~ 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?