2

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?

3
  • I don't think so. I want a command that does it without sending key combinations artificially. Because that depends on the key combination which may be different or not set in KDE environment (not unity as tagged there). such a command may work in every environment (=why I did not mention explicitly KDE environment). But for me KDE is enough. Jan 3, 2014 at 3:54
  • @MinimusHeximus: have you checked the other answers on that question? Jan 3, 2014 at 17:55
  • @AndreaCorbellini: Note two answers there are added after my question. Still answers here are richer. And note this question is about plasma and not unity. btw, this question is now done with. no matter closed or open. Jan 3, 2014 at 18:37

2 Answers 2

2

To show the desktop the command:

wmctrl -k on

To turn it off use

wmctrl -k off
4
  • btw, on and off dashes the hope of simulating KDE show desktop widget which has a toggling nature. Jan 3, 2014 at 4:14
  • strangely, if you execute the command in yakuake then show yakuake all windows are restored...
    – virtualxtc
    Jan 3, 2014 at 4:17
  • couldn't you just use an if else statement to toggle?
    – virtualxtc
    Jan 3, 2014 at 4:18
  • well I intend to attach a hotkey to it which will run the command. So there will be no terminal. About if statement, I'm not sure how to check the condition. well I may write a C++ code which will save the status in a file and on re-execution will read the file to check the status. Not worth the candle. Jan 3, 2014 at 4:28
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.

5
  • I tested it but it always minimizes, and does not restore. Maybe wmctrl -k off is not working well or [[ "$current_mode" == ON ]] is incompatible with it. Jan 3, 2014 at 4:39
  • @MinimusHeximus The issue might be that it isn't being run with Bash and is instead run with sh. See my edits.
    – kiri
    Jan 3, 2014 at 4:42
  • @minerz029 sweet! can you point me to an explanation of the ##* part? I'm assuming it causes it to read the last work after the grepped line or something....
    – virtualxtc
    Jan 3, 2014 at 5:00
  • 1
    @virtualxtc The ${var##exp} returns $var with the longest match of exp deleted from the front of it, where exp is a shell glob. $var is not actually modified. See here for more details and other similar constructs.
    – kiri
    Jan 3, 2014 at 5:02
  • Thanks! I didn't recognize that the space inside the bracket is nessesary until I reviewed the examples in your link.
    – virtualxtc
    Jan 3, 2014 at 5:19

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