Minimize multiple windows at once

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.


I'm not aware of anything that provides exactly what you're looking for, but you can try this kinda ugly workaround by following the steps below.

  1. Set Ubuntu dock to show windows only from the current workspace.
  2. Enable 'minimise on click' on Ubuntu dock. Once you do this, you'll be able to minimise or restore all windows belonging to a specific application from the current workspace by clicking its icon in the dock.
  3. Use different workspaces to group the windows, e.g. keep all the Terminal windows belonging to the first group in workspace 1, second group in workspace 2 and so on.

Ubuntu 19.04 I have not tested this script , feel free to correct me on those keystrokes. you could use a script to minimise the window and other windows by selecting them from a names list and sending the minimise keystroke to them. unfortunately I do not see minimise window shortcut in Gnome keyboard shortcuts. set a shortcut key in Gnome to run this script. keydown alt + space release then m (or enter as minimise is the first in my window min/max/move list) would do the trick though, xdotool keystrokes help here https://www.linux.org/threads/xdotool-keyboard.10528/

#!/bin/bash
names="Firefox Thunderbird Kate Konsole"
echo "$names"
for name in $names
 do
    #         id=$(xdotool search --onlyvisible --name 
"$name")
             id=$(xdotool search --desktop 0 --class  
"$name")
    echo $name $id
if  [ "x$id" = "x" ]
    then
        echo " window not found for "$name""
    else
          xdotool windowactivate --sync $id key  -- 
 clearmodifiers  --delay 100 keydown alt+space 
 xdotool windowactivate --sync $id key  -- 
 clearmodifiers  --delay 100 key enter
     # you can set sleep by a lesser value here like a 
  fraction 0.1   
  sleep 1
  fi
done