wmctrl -s can be used to switch between virtual desktops. Is there a command that shows the desktop? that is a command that will switch between minimizing all windows and restoring them?
Asked
Active
Viewed 3,414 times
2
Minimus Heximus
- 3,648
2 Answers
2
This is an adaptation of virtualxtc's answer with support for toggling.
#!/bin/bash
current_mode="$(wmctrl -m | grep 'showing the desktop')"
if [[ "${current_mode##* }" == ON ]]; then
wmctrl -k off
else
wmctrl -k on
fi
To use, save the above into a file, then mark it executable.
Explanation of above code
#!/bin/bash
This is a shebang comment.
current_mode="$(wmctrl -m | grep 'showing the desktop')"
This captures the output of wmctrl -m piped through grep 'showing the desktop' into the variable $current_mode.
if [[ "${current_mode##* }" == ON ]]; then
wmctrl -k off
else
wmctrl -k on
fi
An if...else... statement in Bash. ${current_mode##* } returns $current_mode with the longest match of anything up until a space deleted from the front of the string. If this returns ON, turns desktop off; else turns desktop on.