-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWaylandReaper.sh
More file actions
47 lines (38 loc) · 1.28 KB
/
WaylandReaper.sh
File metadata and controls
47 lines (38 loc) · 1.28 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
# Define the whitelist of process names
whitelist=(
guake
gnome-shell
# Add more process names to the whitelist as needed
)
# Get the PID of the active window
if ! active_window_pid=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/WindowsExt --method org.gnome.Shell.Extensions.WindowsExt.FocusPID | awk -F"'" '{print $2}'); then
echo "Failed to communicate with GNOME Shell"
exit 1
fi
# Check if the PID is successfully obtained
if [ -z "$active_window_pid" ]; then
echo "Failed to determine the PID of the active window."
exit 1
fi
# Verify if the process exists
if ! ps -p "$active_window_pid" > /dev/null; then
echo "Process $active_window_pid does not exist"
exit 1
fi
# Get the process name associated with the PID
process_name=$(ps -p "$active_window_pid" -o comm=)
# Check against the whitelist
if [[ "${whitelist[@]}" =~ "$process_name" ]]; then
echo "Whitelisted process: $process_name, ignoring"
exit 1
fi
# Try normal termination first
kill "$active_window_pid"
# Wait a short moment to see if the process terminates
sleep 0.5
# Check if process is still running
if ps -p "$active_window_pid" > /dev/null; then
# Force-kill the process if it's still running
kill -9 "$active_window_pid"
fi