Changing Geany window title text

The idea is that I regularly work on a couple of repos at the same time, and can have like five Geany windows open, with three of them showing say 'requirements.txt - […'. I'd prefer to have the window title to start with the project name so I know which window is which project. I thought of patching Geany itself like https://github.com/geany/geany/pull/290, but I am not really proficient in C, so I went for weird Python/Xfce solution.

Here it is:

1. Run:

sudo apt install wmctrl xdotool

2. Save this script anywhere, name it anything, mine is '~/scripts/change geany titles.py'

import subprocess
from time import sleep
 
while True:
    windows_details = subprocess.run(['wmctrl', '-l'], stdout=subprocess.PIPE).stdout.decode('UTF-8')
    for window_details in windows_details.splitlines():
        window_id, _, title = window_details.split(maxsplit=2)
        if '] - Geany' in title:
            new_title = title[title.find(' [')+2:].replace(' (new instance)', '').replace(']','')
            subprocess.run(['xdotool', 'set_window', '--name', new_title, window_id])
    sleep(0.1)

3. To autostart this, as I use Xfce, I created this '~/.config/autostart/geany titles.desktop' file:

[Desktop Entry]
Encoding=UTF-8
Version=0.9.4
Type=Application
Name=geany titles
Comment=change geany window titles to start with the project
Exec=python3 "/home/<your username goes here>/scripts/change geany titles.py"
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false

Hope this helps somebody :)

Print/export