Skip to content

Instantly share code, notes, and snippets.

@brunomiguel
Last active March 18, 2024 01:55
Show Gist options
  • Save brunomiguel/11b0ed80dc88fe171aaac40a644cb8bc to your computer and use it in GitHub Desktop.
Save brunomiguel/11b0ed80dc88fe171aaac40a644cb8bc to your computer and use it in GitHub Desktop.
Manage screensaver and screen blanking statuses on X11
function XScreenManage {
if ! command -v notify-send &> /dev/null; then
echo -e "Warning: notify-send could not be found. Please install it using\
your distribution native package manager. On Arch Linux, you can install it\
with \"sudo pacman -Sy libnotify\""
return 1 2>/dev/null
fi
local blanking() {
blanking_status=$(xset s q | grep -i blanking | cut -d " " -f3-6)
blanking_off="prefer blanking: no"
blanking_on="prefer blanking: yes"
if [[ $blanking_status = $blanking_off ]]; then
echo -e "\n\e[0;93mEnabling screen blanking..."
xset s blank
xset s q | grep -i blanking | cut -d " " -f3-6
notify-send "Screen blanking enabled"
else
echo -e "\n\e[0;93mDisabling screen blanking..."
xset s noblank
xset s q | grep -i blanking | cut -d " " -f3-6
notify-send "Screen blanking disabled"
fi
}
local screensaver() {
screensaver_status=$(xset s q | grep -i timeout | cut -d " " -f3-5)
screensaver_off="timeout: 0"
screensaver_on="timeout: 600"
if [[ $screensaver_status = $screensaver_off ]]; then
echo -e "\n\e[0;93mEnabling screensaver..."
xset s on
xset s q | grep -i timeout | cut -d " " -f3-5
notify-send "Screensaver enabled"
else
echo -e "\n\e[0;93mDisabling screensaver..."
xset s off
xset s q | grep -i timeout | cut -d " " -f3-5
notify-send "Screensaver disabled"
fi
}
local status() {
notify-send "$(xset s q | grep -i blanking | cut -d " " -f2-6)"
notify-send "$(xset s q | grep -i timeout | cut -d " " -f3-5)"
xset s q | grep -i blanking | cut -d " " -f2-6
xset s q | grep -i timeout | cut -d " " -f3-5
}
case "$1" in
-b)
blanking;;
-s)
screensaver;;
-q)
status;;
-h | *)
echo -e "-b\ttoggle screen blanking\n-s\ttoggle screensaver\n-q\t\
query screen blanking and screensaver status\n-h\tdisplay help"
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment