This is an fundamental X11 limitation: open popup menus inhibit all global keybindings and even screen locking. It is fixed by switching to a Wayland-based session.
I certainly must have tried the wrong bash script - yours work like a charm!
Thank you very much, Marius.
Could you either give me some keywords or a link or a quick explanation why printing some “control keys” are able to modify the terminal tab? Reminds me a little bit of the PS1 variable.
While we are at it… sometimes, when I ssh into another server, my tab title gets changed…
Most terminal emulators implement xterm’s control sequences. ESC [ is the prefix for Operating System Commands (OSC). OSC 0 sets the window title in xterm (which doesn’t have tabs).
One common use of this (enabled by default in the ~/.bashrc of some distros) is to have PS1 emit the OSC 0 sequence to set the terminal title to display the current working directory. This might be what you’re observing when you SSH somewhere.
In fact you ought to be seeing this locally too, because in Ubuntu the default .bashrc also does this!, when $TERM is set to xterm* or rxvt*. You must be using a custom .bashrc, or maybe a different shell, or maybe some terminal multiplexer (screen/tmux) that changes $TERM.
You can run gnome-screenshot and ask it to take a whole screen screenshot after a delay. Then you can open a menu and wait for a flash. That works at least on X; though you need to crop it in GIMP or some other app.