I would like a global keyboard shortcut super+down to minimize all windows except the active one, so that I can see that window with just the desktop in the background. A nice extra would be to simultaneously position the window to the center of the screen.

I am on Kubuntu 19.10 with Plasma 5.18.3.

I am aware of the "Shake" KWin script, but I want a keyboard shortcut.

My idea was to write a script to minimize all windows, then bring the last active window back to focus and center it via keystrokes using xdotool, then configure a custom shortcut to run this script.

My script is as follows:


active=$(xdotool getactivewindow)  # remember active window
xdotool key super+shift+d          # minimize all windows
xdotool windowactivate $active     # bring back last active window
xdotool key super+c                # center active window

super+shift+d is a global shortcut I configured for the KWin script "Minimize all" I previously activated, super+c the one for the "Move window to Center" KWin script I installed and activated as well. Individually, these key combinations work, both when hitting them manually and when simulating them with xdotool.

My custom shortcut does actually start the script; however, it will only minimize the windows and not bring the last window back to focus.

Running the script from the terminal and inserting echo statements between the lines reveals that the script runs through until the end, just that the last two lines don't seem to have any effect, but without giving any error message. Running the commands echo $(xdotool getactivewindow) and xdotool windowactivate 150994951 individually did what they were supposed to as well, so my best guess is that I did something wrong about passing the active variable to the windowactivate command, but I can't figure out what.

What did I do wrong?

Is there a more elegant way to define a custom shortcut for the procedure described above?

2 Answers 2


I am not sure why your script did not work, maybe windowactivate executes before the previous command manages to minimize all windows?

Here is a bash script that might work for you:


active_window_id=$(xdotool getactivewindow)
for window_id in $(xdotool search --onlyvisible ".*")
    if [ $window_id != $active_window_id ]
        xdotool windowminimize $window_id

It might also look better as it does not quickly minimize and maximize your active window.

Edit: I missed the centering part, but that should not be a problem.

  • This works, thank you. (Though I'd like to wait with an accept in the hope someone comes up with a good way of adding the centering function -- appending the xdotool command doesn't always work.) Commented May 1, 2020 at 20:33

You might be looking for wmctrl -k on. It minimizes everything at the same time with a single _NET_SHOWING_DESKTOP request.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .