1

It's rather hard to do it. wmctrl needs to know the window title in order to operate on it, but it is damn hard to know the title of any terminal emulator, be it gnome-terminal, rxvt, xterm...

Because

  • Often .bashrc specify PS1 to change window's title to current path.
  • editor like VIM changes window's title to the current file.
  • command line tools like mosh love to change window title.
  • ssh into another machine, usually the shell (bash) on the remote host changes the title. So if you remove title-changing part of PS1 you need to do it to every computer you may connect to -- a long list of which for any seasoned sysop.
  • Even if you run GNU Screen in a terminal, the session inside screen can still change the title of the outter terminal emulator.

fluxbox exceptionally allows referring to a window by other properties of the X-window (xwininfo) than title. but switching to fluxbox is too big a change for this small need.

In short, there seems to be no way to know the title of the terminal emulator window ... or, is there one?

  • Have you tried using PID file? This might be the way to go. – roomcays Dec 16 '13 at 14:12
  • Consider using yakuake… it's a terminal that always pops up on a hotkey. Maybe this helps. – mirabilos Dec 24 '13 at 0:01
1

Many terminal emulators (at least Xterm, Rxvt, Gnome-terminal and Konsole) set the WINDOWID environment variable to the X11 window ID. You can pass this window ID to wmctrl:

wmctrl -i -a "$target_window_id"

Beware that inside a Screen or Tmux session, you'll get the window ID where you initially started the multiplexer, not the one where it's currently attached.

  • Thank you. The command I finally used to launch xterm is:xterm -e 'echo $WINDOWID > /tmp/xterm.wid ; bash' and the command to switch to it is xargs wmctrl -i -a < /tmp/xterm.wid – Tankman六四 Dec 26 '13 at 14:05
0

Use wmctrl -l before and after the start of the terminal emulator and store the output both times. The line differing between the outputs will give you the ID of the window, using cut to automatically retrieve the first value (it is the ID).

This ID is independent of the title of the terminal emulator window. You can use that to do wmctrl -a ID until you close the terminal emulator and the ID is no longer valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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