Sun, 13 Oct 2013

windowtitle .:.permalink.:.

A simple python utility to rename the xwindow title bar to something else.

If you're like me you easily end up with dozens of terminal sessions open and most are just named according to their respective current directory.

I hate that when alt-tabbing to find the one I want, hence this tool to rename them to something meaningful.

Code requires xdotool and is written for python3 and it's subprocess.getoutput module

#!/usr/bin/python3
import sys
import os
from subprocess import *

xdoOut=getoutput('xdotool selectwindow')
if len(xdoOut)>0:
    winID =xdoOut.split('\n')[-1]
    xdocmd="xdotool set_window --name '%s' --icon-name '%s' %s"%(sys.argv[1],sys.argv[1],winID)
    xdoNameOut=getoutput(xdocmd)

if you're python2 import the commands module instead:

#!/usr/bin/python2
import sys
import os
from commands import *

xdoOut=getoutput('xdotool selectwindow')

if len(xdoOut)>0:
    winID =xdoOut.split('\n')[-1]
    xdocmd="xdotool set_window --name '%s' --icon-name '%s' %s"%(sys.argv[1],sys.argv[1],winID)
    xdoNameOut=getoutput(xdocmd)

To use it just issue a

windowtitle titleyouwant

Your cursor will change to a selection icon, pick the target window you want to rename and poof..it's renamed.

happy renaming!

Posted at: Sun, 13 Oct 2013 | category: /itsec