Ubuntu – How to change the window titles (as used by wmctrl)

command linewindowworkspaces

I am using wmctrl to move applications after I have launched them such that I do not have to do this manually for, for example, several text editors and web browsers and pdf viewers and terminals. I am issuing the following wmctrl command to move applications around

wmctrl -r <title> -e <x>,<y>,0,-1,-1

where < x > and < y > are the horizontal and vertical target coordinates, and < title > is the name of the application as returned by wmctrl -l. If I launch two copies of google chrome via the below commands,

google-chrome &
google-chrome &

then issue the command

wmctrl -l 

the window names returned are

0x03c06fd9  0 main New Tab - Google Chrome
0x03c0703d  0 main New Tab - Google Chrome

now if I try to move one of those to an arbitrary coordinate, lets say 100,100, with the following command

wmctrl -r "Google Chrome" -e 100,100,0,-1,-1

It will, if you haven't already guessed it, move THIS google chrome window I am currently typing in, as I opened it prior to the other two.

Is there some way to assign these window titles when launching from the command line, or to reset them later. I need to change the names to something like

Google Chrome 1
Google Chrome 2
Google Chrome 3

Note there are two ways around this that I am aware of, however, I do not like either of them, for they could lead to problems if the OS launches a program in the background.

  1. Instead of using the title, use the numerical window ID via the -i command.
  2. Use the string :ACTIVE: to use the active window

Best Answer

Use the xttitle program from the xttitle package. Note the TWO "t"s in xttitle. Well, actually, there are 3 "t"s... but I've only had trouble mistyping the first two.

Here's an example from my ~/.bashrc, in which I override the cd builtin, and use xttitle to put the current directory in my window title:

# from the "xttitle(1)" man page - put info in window title
update_title()
{
    [[ $TERM = xterm ]] || [[ $TERM = xterm-color ]]  && xttitle "[$$] ${USER}@${HOSTNAME}:$PWD"
}

cd()
{
    [[ -z "$*" ]] && builtin cd $HOME
    [[ -n "$*" ]] && builtin cd "$*"
    update_title
}