Last active
June 12, 2019 08:08
-
-
Save jshiell/b56cfce04b0b696fb98ba1fa7889f947 to your computer and use it in GitHub Desktop.
Wall monitor power saving script (XRandR)
This file contains 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 | |
set -euo pipefail | |
IFS=$'\n\t' | |
DISPLAY="${DISPLAY:-:0}" | |
turn_off_all_screens() { | |
for MONITOR in $(xrandr -d :0 --listmonitors | awk '{print $4}'); do | |
xrandr -d "$DISPLAY" --output "$MONITOR" --off | |
done | |
} | |
turn_on_all_screens() { | |
for MONITOR in $(xrandr -d :0 --listmonitors | awk '{print $4}'); do | |
xrandr -d "$DISPLAY" --output "$MONITOR" --auto | |
done | |
} | |
main() { | |
if ! xrandr --help >/dev/null 2>&1; then | |
echo "xrandr is not on the path; exiting..." | |
exit 1 | |
fi | |
if ! xrandr -d "$DISPLAY" --version >/dev/null 2>&1; then | |
echo "xrandr does not appear to work with display $DISPLAY; 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