Hostname in X11 window title How can I make the hostname show in the title of an X11 window? 

In Linux environments, ssh -Y foohost; ...; bar-gui will open an xwindow for the program with the title "bar-gui (on foohost)". That is, the hostname is automatically appended to the X11 window title when it is running on a remote system. I am running programs on multiple remote systems and I need to tell them apart.

Example: Note the hostname in the title of the window on the right. 

I would like to have the same behavior from a mac client.

(I am not looking to change the terminal title.)

Workaround: xdotool can be used to manually change the title of an x window.

ssh -Y foohost
...
bar-gui &amp;
pid="$!"
# Wait for bar-gui to actually load
win=$(xdotool search --pid "$pid")
xdotool set_window --name "bar-gui (on foohost)" "$win"


This workaround is not ideal so I'm not making it an answer. It needs xdotool installed to work. This would not work great as a bash script or function. There are possibly better ways to use xdotool, but this was the first thing I got working.

Note: Doing ... --name "bar-gui (on foohost)" ... from a linux desktop would cause the title to appear as "bar-gui (on foohost) (on foohost)" because it still appends the hostname automatically. 

I am still looking for the mac desktop to automatically include the hostname of remote x11 applications in the window title.
This depends on shell configuration and the exact terminal involved; most things support XTerm Control Sequences though terminals can be configured to deny the use of those escape sequences. What Linux systems often have is shell configuration (usually under /etc/profile.d) that automatically runs the escape sequence to set the title to the hostname. This can also be done manually:

printf "\033]2;this is a test\007"


which should set the title



if not, you'll need to configure the terminal to allow that escape sequence, which will be under the preferences or in a configuration file somewhere, depending.

This can be done automatically from a shell configuration file by generating the appropriate escape sequence with the hostname (or whatever other data you might want):

printf "\033]2;%s\007" $(hostname)