-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloseWS.sh
More file actions
executable file
·47 lines (39 loc) · 1.45 KB
/
Copy pathcloseWS.sh
File metadata and controls
executable file
·47 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# ==============================================================================
# Workspace Closer (Close all windows on the current virtual desktop)
# ==============================================================================
get_windows_json() {
python3 -c "
import gi
gi.require_version('Gio', '2.0')
from gi.repository import Gio
try:
bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None, 'org.gnome.Shell', '/org/gnome/Shell/Extensions/Windows', 'org.gnome.Shell.Extensions.Windows', None)
print(proxy.call_sync('List', None, Gio.DBusCallFlags.NONE, -1, None).unpack()[0])
except:
print('[]')
" 2>/dev/null
}
close_window() {
local ID=$1
gdbus call --session --dest org.gnome.Shell \
--object-path /org/gnome/Shell/Extensions/Windows \
--method org.gnome.Shell.Extensions.Windows.Close \
"$ID" >/dev/null 2>&1
}
echo "Scanning for windows on current workspace..."
WINDOWS=$(get_windows_json)
# Filter IDs for windows in the current workspace
# Note: This includes minimized windows if they belong to this workspace
IDS=$(echo "$WINDOWS" | jq -r '.[] | select(.in_current_workspace == true) | .id')
if [ -z "$IDS" ]; then
echo "No windows found on the current workspace."
exit 0
fi
echo "Closing $(echo "$IDS" | wc -l) windows..."
for id in $IDS; do
echo " > Closing window ID: $id"
close_window "$id"
done
echo "Done."