From 4b59864dde9ef10d227cdacdbe5803a7d05e52fe Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Sun, 10 Jul 2022 21:56:21 -0500 Subject: [PATCH] Use at instead of cron --- brightness-by-daylight.sh | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/brightness-by-daylight.sh b/brightness-by-daylight.sh index 9e70f2a..6e4b058 100644 --- a/brightness-by-daylight.sh +++ b/brightness-by-daylight.sh @@ -9,18 +9,13 @@ # ~/.config/latlong.toml # latitude="0.000000N" # longitude="0.000000E" +# scriptdir= -# Add the following to crontab to make it run automatically and properly - -# @reboot crontab -# 0 0,12 * * * crontab +# 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.) # 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 - -# To run this script whenever and HDMI cable is connected, copy this file to /usr/local/bin/ and run 'chmod +x /usr/local/bin/brightness-by-daylight.sh' -# Then create the file /etc/udev/rules.d/89-hdmi_brightness.rules with the following content : -# KERNEL=="card0", SUBSYSTEM=="drm", ACTION=="add", RUN+="/usr/local/bin/brightness-by-daylight.sh" -# Then run 'udevadm control --reload-rules' and reboot +# (Sometimes I forget to turn on the monitor when I start my PC, so this is better than having a crontab) confdir="/home/sintan/.config" @@ -35,17 +30,10 @@ fi # otherwise adjust brightness immediately if [ "$1" == "crontab" ]; then - if test -f /tmp/brightness-crontab; then - exit + if [ $(sunwait poll $latitude $longitude) == "DAY" ]; then + at -m $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $6}') <<< "ddcutil setvcp 10 40 && $scriptdir/brightness-by-daylight.sh crontab" else - if [ $(sunwait poll $latitude $longitude) == "DAY" ]; then - echo "Waiting for sunset at" $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $6}') > /tmp/brightness-crontab - sunwait wait set offset 10 $latitude $longitude && ddcutil setvcp 10 40 - else - echo "Waiting for sunrise at" $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $4}') > /tmp/brightness-crontab - sunwait wait rise offset 10 $latitude $longitude && ddcutil setvcp 10 70 - fi - rm /tmp/brightness-crontab + at -m $(sunwait report 35.221050N 97.445938W | grep "Daylight:" | awk '{print $4}') <<< "ddcutil setvcp 10 70 && $scriptdir/brightness-by-daylight.sh crontab" fi else if [ $(sunwait poll $latitude $longitude) == "DAY" ]; then