Skip to content

Instantly share code, notes, and snippets.

@jshiell
Last active July 15, 2019 07:51
Show Gist options
  • Save jshiell/48f3848ee0841a57f1ff62863723848e to your computer and use it in GitHub Desktop.
Save jshiell/48f3848ee0841a57f1ff62863723848e to your computer and use it in GitHub Desktop.
Wall monitor power saving script (Wayland/Ubuntu 19.04)
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
turn_off_all_screens() {
busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 3
}
turn_on_all_screens() {
busctl --user set-property org.gnome.Mutter.DisplayConfig /org/gnome/Mutter/DisplayConfig org.gnome.Mutter.DisplayConfig PowerSaveMode i 0
}
main() {
XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-}
if [[ -z "$XDG_RUNTIME_DIR" ]]; then
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
fi
if ! busctl --version >/dev/null 2>&1; then
echo "busctl could not be version checked; exiting..."
exit 1
fi
local WAKE_START_HOUR=8
local WAKE_END_HOUR=18
local SATURDAY=6
local CURRENT_HOUR=$(date +"%k")
local DAY_OF_WEEK=$(date +"%u")
if [[ "$CURRENT_HOUR" -ge "$WAKE_START_HOUR" && "$CURRENT_HOUR" -lt "$WAKE_END_HOUR" && "$DAY_OF_WEEK" -lt "$SATURDAY" ]]; then
turn_on_all_screens
else
turn_off_all_screens
fi
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment