I have several applications open. Running wmctrl and piping the output to awk lists the window IDs (excluding "sticky" windows) like this:
$ wmctrl -l | awk ' !/-1/ { print $1 } '
0x00a00018
0x04800005
0x04e00005
0x04400003
0x05000003
0x0540002b
0x05a00012
0x05800002
0x05c00003
$
I can send this output to wmctrl to close all these windows:
windows without content that needs to be saved and windows that don't need a response will be closed without asking me but
windows such as those of editors with unsaved content or terminals running a process will be closed "gracefully": the respective application will present a window allowing me to save changes or discard changes or to inform me of a process that's still running.
The following script, assigned to a suitable shortcut, works:
#!/bin/bash
list=$(wmctrl -l | awk ' !/-1/ { print $1 } ')
for i in ${list[@]}
do
wmctrl -i -a $i
wmctrl -i -c $i
done
I found that the simpler (to me) for i in $list
also works.
Is there any reason to prefer one over the other?
"sticky" and "gracefully" are terms from man wmctrl
.
list
like it was an array, but it is a normal variable. – pLumo Oct 17 '19 at 11:46xargs
– Stephen Boston Oct 17 '19 at 12:07for i in $list
meansfor i in ${list[0]}
if it is an array, it will only get you the first element – Oct 18 '19 at 07:37for i in $(wmctrl -l | awk '!/-1/ { print $1 }'); do echo $i; done
is how I always do it. – RonJohn Oct 18 '19 at 11:40