Sample Header Ad - 728x90

Script/keyboard shortcut to minimize all other windows

4 votes
2 answers
3977 views
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: #!/bin/bash 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?
Asked by Natalie Clarius (369 rep)
Apr 28, 2020, 12:15 PM
Last activity: Jul 19, 2023, 12:44 PM