Xfce Forum

Sub domains
 

You are not logged in.

#1 2025-07-22 21:52:43

advice1010
Member
Registered: 2023-02-19
Posts: 134
LinuxChrome 130.0

Window Manager - Close all open windows (SOLVED)

I was wondering if anyone knew of a way to setup a hotkey that would close all windows at the same time?
XWM only has a hotkey that allows one window to be closed at a time.
I was not sure if maybe there was a hidden way to achieve this?
Imagine this would require some kind of Bash script?

Would be for all programs "window buttons" opened in panel, I guess in current workspace?
Not sure if there are more specific ways?
-Only current Workspace
-All programs opened in all Workspaces

Thank You

Last edited by advice1010 (2025-08-16 17:16:02)

Offline

#2 2025-07-22 22:16:10

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 12,123
LinuxFirefox 140.0

Re: Window Manager - Close all open windows (SOLVED)

You can use the following script (it requires wmctrl). Make it executable and assign it to keyboard shortcuts:

Keyboard Shortcut #1: Close all windows

/path/to/script all

Keyboard Shortcut #2: Close only windows on current workspace

/path/to/script current

Script

#!/usr/bin/env bash
# 	script to close windows
#	requires: wmctrl
#	parameters: all = all open windows
#				current = only on current workspace

case $1 in
	all)
		for w in $(wmctrl -lv | grep -v " -1 " | awk '{print $1}')
		do 
			wmctrl -ic $w
		done
	;;
	current)
		CURRENT=$(wmctrl -d | grep "*" | awk '{print $1}')
		for w in $(wmctrl -lv | grep -v " -1 " | grep " $CURRENT " | awk '{print $1}')
		do 
			wmctrl -ic $w
		done

	;;
	*)
		echo "You need to specify either "all" (to close all windows) or "current" to close only the windows on the current workspace."
	;;

esac

exit 0

Note that the "wmctrl -ic" command will try to gracefully close windows - not force close them.


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2025-08-02 20:20:10

advice1010
Member
Registered: 2023-02-19
Posts: 134
LinuxChrome 130.0

Re: Window Manager - Close all open windows (SOLVED)

@ToZ
Thank you so much for providing this script.
I was not able to test the Workspace part yet because I am still working on Workspace setup, but was able to test the ALL version, which works great.

I am really glad I asked for two things in this case.
I do not think I have ever seen a Bash script that had the capability of using options when running the script like this.
I generally have only seen options within the Bash script files.  Did not even know this was possible, wow thank you also for bringing this to my attention smile

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 535.68 KiB (Peak: 536.96 KiB) ]