Close all Windows at Once

Forum rules
Before you post please read how to get help
Post Reply
User avatar
lisabonne citadel
Level 3
Level 3
Posts: 126
Joined: Fri Oct 13, 2017 5:13 am

Close all Windows at Once

Post by lisabonne citadel » Fri Nov 17, 2017 8:43 am

this script was taken from askubuntu and official manjaro forum.

This is great to close all windows opened but at the same time all you dont..
first check all windows you dont intend to be closed doing this in terminal
wmctrl -l

if you dont have wmctrl installed you can pick up on

edit the script and change cinnamon-panel by your desktop panel name
add either the intended window to not be closed as for example of mine ... Docky

you can put on panel as command launcher

DOWNLOAD script ... a4D-0dSXul
DOWNLOAD panel icon ... 8cL6hL3qoC
Last edited by Moem on Fri Nov 17, 2017 8:48 am, edited 1 time in total.
Reason: pretend => intend

User avatar
Level 1
Level 1
Posts: 17
Joined: Mon Jan 12, 2015 10:17 am

Re: Close all Windows at Once

Post by Misko_2083 » Fri Nov 17, 2017 2:41 pm

Instead of filtering with app name you could filter out X window properties.
This asks to close gracefully only normal windows and dialogs.
Conky, Docky xfce and other stuff should be safe in theory.

Code: Select all


#Check dependancies
for DEP in /usr/bin/{zenity,xprop,wmctrl,awk} /bin/{grep,echo}; {
	[ -x "$DEP" ] || {
		echo "$LINENO" "Dependency '$DEP' not met."

[ $DEPCOUNT -gt 0 ] && exit 1

# With process substitution output from "wmctrl -l" is redirected to file descriptor 3
# while loop reads  "win_id" and "display" variables from file descriptor 3
while read -r win_id display text <&3

	# filter windows with win_id that has X window properties of type normal or dialog
	if xprop -id $win_id | grep -e "^_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_NORMAL" \
                                    -e "^_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG" &>/dev/null
		# Get WM_CLASS X window property
		wm_class=$(xprop -id $win_id WM_CLASS | awk -F'"' '{print $4}')

		# if WM_CLASS is a "Wrapper"
		if [[ "${wm_class}" == "Wrapper" ]]
			# Get WM_CLASS X window property _NET_WM_NAME
			wm_class=$(xprop -id $win_id _NET_WM_NAME | awk -F '"' '{print $2}')

			echo "#Closing: $wm_class $text" $"\n ID: $win_id on display :$display"
			echo "#Closing: $wm_class $text" $"\nID: $win_id on display :$display"

		# Gracefully ask for close
		wmctrl -ic "$win_id"
		sleep 2
done 3< <(wmctrl -l -x | awk '{print $1,$2,substr($0, index($0,$4), 32)}') | zenity --progress --pulsate --auto-close

# Close file descriptor 3
exec 3<&-

Anyhow, I have a hunch that @Xenopeek probably has a better way to do this. :)

Post Reply

Return to “Scripts & Bash”