Ubuntu – Minimize multiple windows at once

gnome-shellminimizewindow

I am using Ubuntu 18.04 with GNOME. I would like to know if there is any functionality that allows to associate multiple windows in such a way that when one of the windows is minimized all the other are too and when the window is restored all the others too.

I.e. I am working with multiple terminal windows and I would like to group the terminals in N groups, in such a way that when I minimize a terminal window all other terminal windows that belong to that group get minimized too.

Best Answer

The following procedure is only for $XDG_SESSION_TYPE x11.

Notes:

  • It uses xdotool which is in the Universe repository.
  • It assumes you've categorized your terminal windows in such a way that each group has a common string in the title (not present in any other open windows).
  • In the example below, there are two groups each with three open gnome-terminal windows:
    • Earth 1
    • Earth 2
    • Earth 3 and
    • Wind 1
    • Wind 2
    • Wind 3

Important:
To ensure that the terminal window's title does not change, I had to first comment out the following lines from ~/.bashrc. If this is not done, the title will reflect the current working directory instead of retaining the title you set:

case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

I named each window using

echo -en "\033]0;New title\a"

Note that xdotool, as used here, won't handle windows named using

wmctrl -r :ACTIVE: -N "New title"

See the answer to Setting terminal window's title: wmctrl versus xdotool for a thorough explanation.

The following animated gif will illustrate using another "master" terminal, located at the top of the screen in the image, to issue code to minimize or maximize a particular group of windows.

To do so, I added the following functions to my ~/.bashrc:

mmm(){
    echo "enter KEYWORD" && read KEYWORD && xdotool search --name --onlyvisible "$KEYWORD" > /tmp/tmp.txt
}

xwn() {
    while read p; do xdotool windowminimize "$p"; done </tmp/tmp.txt
}

xwx() {
    while read p; do xdotool windowactivate "$p"; done </tmp/tmp.txt
}
  • mmm uses xdotool to search for the string "KEYWORD" provided by the user. "earth" in this example, is common to one group of terminal windows to be acted on. xdotool produces their window identifiers which is directed to a temporary file.
  • xwn uses xdotool's windowminimize action to minimize the windows specified in the temporary file.
  • xwx uses xdotool's windowactivate action to maximize the windows specified in the temporary file.
  • Note that, depending on what else has been done, it maybe necessary to run mmm immediately before xwn or xwx.

Using xdotool to minimize/maximize groups of terminal windows


I had to use mogrify -type Grayscale -depth 7 *.png to scale down the size of the gif.