After trying your method, I found that although the main window title has been changed, but there are still some labels following after the new title name.
For example, in my case, my window title becomes "$newTitleName ", in which "" is a redundant label which I don't want.
Do you have any idea to remove these labels?
Anyway, thx for your useful work ;)