1
0
Fork 0
mirror of https://github.com/SinTan1729/random.git synced 2024-12-27 05:28:37 -06:00
random/brightness-by-daylight.sh

49 lines
2.1 KiB
Bash
Raw Normal View History

2022-06-26 19:22:50 -05:00
#!/bin/sh
# This is a script to set my external monitor's brightness
# to high (70%) or low (40%) automatically according to day/night.
# It uses ddcutil to access the monitor's settings and sunwait to know
# if it's day or night. It expects a file in the following format in
# the .config directory (the values should be according to location)
# ~/.config/latlong.toml
# latitude="0.000000N"
# longitude="0.000000E"
2022-07-10 21:56:21 -05:00
# scriptdir=<location-of-this-script>
2022-07-11 23:52:48 -05:00
# high=70
# low=40
2022-06-26 19:22:50 -05:00
2022-07-10 21:56:21 -05:00
# Just run this script one manually to set it up to run perpetually (hopefully) using 'at'
# (Some distros don't come with 'at' preinstalled, so you might need to install 'at' and enable the 'atd' service.)
2022-06-26 19:22:50 -05:00
# It might also be a good idea to add this script's location to your DE's autostart list, or to '.profile' so that it launches on system login
2022-07-10 21:56:21 -05:00
# (Sometimes I forget to turn on the monitor when I start my PC, so this is better than having a crontab)
2022-06-26 19:22:50 -05:00
confdir="/home/sintan/.config"
if test -f $confdir/latlong.toml ; then
source $confdir/latlong.toml
else
echo "No location config found!"
2022-06-26 21:53:58 -05:00
exit
2022-06-26 19:22:50 -05:00
fi
2022-07-11 21:19:33 -05:00
# Check if we want to access the scheduler. If yes, create a schedule using `at`,
2022-06-26 21:53:58 -05:00
# otherwise adjust brightness immediately
2022-07-11 21:19:33 -05:00
if [ "$1" == "scheduler" ]; then
2022-07-10 21:56:21 -05:00
if [ $(sunwait poll $latitude $longitude) == "DAY" ]; then
2022-07-11 20:58:12 -05:00
# +1 minute is so that the next schedule is set up properly (or sunwait reports day/night in a misleading way)
2022-07-11 23:52:48 -05:00
at -m $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $6}') +1 minute <<< "ddcutil setvcp 10 $low && $scriptdir/brightness-by-daylight.sh scheduler"
2022-06-26 19:22:50 -05:00
else
2022-07-11 23:52:48 -05:00
at -m $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $4}') +1 minute <<< "ddcutil setvcp 10 $high && $scriptdir/brightness-by-daylight.sh scheduler"
2022-06-26 19:22:50 -05:00
fi
else
if [ $(sunwait poll $latitude $longitude) == "DAY" ]; then
2022-07-11 23:52:48 -05:00
ddcutil setvcp 10 $high
echo "Monitor brightness set to $high%, since it's day time."
2022-06-26 19:22:50 -05:00
else
2022-07-11 23:52:48 -05:00
ddcutil setvcp 10 $low
echo "Monitor brightness set to $low%, since it's night time."
2022-06-26 19:22:50 -05:00
fi
fi