Last active
September 3, 2026 19:06
-
-
Save vdbsh/a9f0723708a4393d42a0d768d831c4df to your computer and use it in GitHub Desktop.
Old-school screensaver functionality for GNOME/Wayland desktops
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # afterdark.sh: Old-school screensaver functionality for GNOME/Wayland desktops | |
| # This script will run arbitrary command after specified time period, if there is no inhibiting applications detected | |
| # Started process will be terminated at the first sight of user activity | |
| # You supposed to launch something like full-screen video or cmatrix :) | |
| start_after=15 # minutes | |
| cmd="mpv /home/test/Videos/after_dark.mp4 --fs --loop --no-osc" | |
| lock_screen=false | |
| get_idle_minutes() { | |
| idle_time=$(dbus-send --print-reply --dest=org.gnome.Mutter.IdleMonitor \ | |
| /org/gnome/Mutter/IdleMonitor/Core org.gnome.Mutter.IdleMonitor.GetIdletime | grep -Po '(?<=uint64\s)\d+') | |
| if [ -n "$idle_time" ]; then | |
| echo "$idle_time" / 60000 | bc | |
| else | |
| echo "0" | |
| fi | |
| } | |
| get_inhibitors() { | |
| for i in $(dbus-send --print-reply --dest=org.gnome.SessionManager \ | |
| /org/gnome/SessionManager org.gnome.SessionManager.GetInhibitors | grep -Po 'Inhibitor\d+'); do | |
| if dbus-send --print-reply --dest=org.gnome.SessionManager \ | |
| /org/gnome/SessionManager/"$i" org.gnome.SessionManager.Inhibitor.GetFlags | grep -q 'uint32\s8'; then | |
| true; return | |
| fi | |
| done | |
| false; return | |
| } | |
| while :; do | |
| if [ "$(get_idle_minutes)" -ge $start_after ] && [ -z "$screensaver" ]; then | |
| if ! get_inhibitors; then | |
| gnome-session-inhibit $cmd & | |
| screensaver=$! | |
| fi | |
| elif [ "$(get_idle_minutes)" -lt $start_after ] && [ -n "$screensaver" ]; then | |
| if $lock_screen; then | |
| dbus-send --type=method_call --dest=org.gnome.ScreenSaver \ | |
| /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock | |
| fi | |
| pkill -P $screensaver | |
| screensaver="" | |
| fi | |
| sleep 1 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know if there is a way to make a PR on a GIST. Here it is manually, just some grammar fixes.
3 - # afterdark.sh: Old-school screensaver functionality for GNOME/Wayland desktops
4 - # This script will run arbitrary command after specified time period, if there is no inhibiting applications detected
5 - # Started process will be terminated at the first sight of user activity
6 - # You supposed to launch something like full-screen video or cmatrix :)
3 + # afterdark.sh: Old-school screensaver functionality for GNOME/Wayland desktops.
4 + # This script will run an arbitrary command after a specified time period if there are no inhibiting applications detected.
5 + # Started process will be terminated upon user activity.
6 + # You should launch something like full-screen video or cmatrix :)
Also, I can't remember why I changed this next part, maybe your syntax here is deprecated in new versions of MPV?
Also, using $HOME here is a good idea: "$HOME Variable: An environment variable that stores the full path of the home directory. It is often preferred in scripts because it remains reliable when quoted (e.g., "$HOME")."
9 - cmd="mpv /home/test/Videos/after_dark.mp4 --fs --loop --no-osc"
9 + cmd="mpv --fs --loop --no-osc /$HOME/Videos/after_dark.mp4"