From 6efd805cd847304e5a5c3ea92b650b9328ef0408 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Wed, 25 Nov 2020 03:42:27 +0100 Subject: [PATCH] update description --- README.org | 31 ++++++++++++++++++++----------- nightlight | 9 +++++++++ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.org b/README.org index 1675a5a..4058d42 100644 --- a/README.org +++ b/README.org @@ -3,17 +3,18 @@ :header-args: :tangle nightlight :shebang "#!/bin/sh" :END: - This is a shell script for automatically setting the screen colors and brightness based on daytime. + This is a shell script for automatically setting the screen colors and brightness, based on daytime. The script is created via literate programming. You can find the code below. ** Usage - 1. Obtain your location code from [[https://weather.codes/search/][here]] and paste it into the script - 2. Get the IDs of your displays with =xrandr --listmonitors= and paste them into the script - 3. (Optionally) set the fading window which specifies the amount of minutes in which the screen is dimmed - 4. Make sure the script is executable (=chmod +x nightlight=) and run it with =./nightlight= + 1. Make sure the [[*Requirements][requirements]] are fulfilled + 2. Obtain your location code from [[https://weather.codes/search/][here]] and paste it into the script + 3. Get the IDs of your displays with =xrandr --listmonitors= and paste them into the script + 4. (Optionally) set the fading window which specifies the amount of minutes in which the screen is dimmed + 5. Make sure the script is executable (=chmod +x nightlight=) and run it with =./nightlight= If you are unhappy with the display settings, you can revert them always by stopping the script and calling the following command manually. Please adjust your display ID and call for every display seperately. @@ -27,13 +28,18 @@ Configuration is currently done via editing the script directly or editing this file and then tangling it with Emacs (=C-c C-v t=). #+BEGIN_SRC sh + # SETTINGS + # Edit from here --> + location="GMXX0128" # Location code (get it from https://weather.codes/search/) displays=("eDP-1-1") # Displays e.g. ("eDP-1-1" "eDP-1-2") (get displays with "xrandr --listmonitors") window=60 # Fading window in minutes - #+END_SRC + + # <-- to here + #+END_SRC ** Requirements - + - [[https://www.gnu.org/software/wget/][Wget]] :: Used for getting sunrise and sunset times - [[https://www.gnu.org/software/bc/][bc]] :: Used for floating point calculations - [[https://xorg.freedesktop.org/][xrandr]] :: Used for setting screen colors and brightess, usually shipped with X.Org @@ -49,18 +55,22 @@ then echo -ne "\e[1mbc\e[0m was not found, please install it" exit 1 + elif ! command -v xrandr &> /dev/null + then + echo -ne "\e[1mxrandr\e[0m was not found, are you using X.Org?" + exit 1 fi #+END_SRC ** Local variables - The file containig the sunrise and sunset is stored in =/tmp=. + The file containing the sunrise and sunset is stored in =/tmp=. #+BEGIN_SRC sh file=/tmp/$location #+END_SRC - To make calculations easier, we scale the fading window down to seconds (=* 60=) and divide it in half (=* 0.5=). + To make calculations easier, we scale the fading window down to seconds (=*60=) and divide it in half (=*0.5=). This results in a multiplication with =30=. #+BEGIN_SRC sh @@ -73,7 +83,7 @@ - =sunrise= :: Time in seconds since the Unix epoch until sunrise - =sunset= :: Time in seconds since the Unix epoch until sunset - =now= :: Time in seconds since the Unix epoch until now - - =value= :: Dim value in range [0:1] (0 at day, 1 at night, values in between if in interval around sunrise or sunset) + - =value= :: Dim value in range [0:1] (0 at day, 1 at night, values in between if in window around sunrise or sunset) ** Get times @@ -132,7 +142,6 @@ } #+END_SRC - ** Set display For setting the display values, we need to calculate the current RGB colors and brightness. diff --git a/nightlight b/nightlight index c440089..51fd100 100755 --- a/nightlight +++ b/nightlight @@ -1,8 +1,13 @@ #!/bin/sh +# SETTINGS +# Edit from here --> + location="GMXX0128" # Location code (get it from https://weather.codes/search/) displays=("eDP-1-1") # Displays e.g. ("eDP-1-1" "eDP-1-2") (get displays with "xrandr --listmonitors") window=60 # Fading window in minutes +# <-- to here + if ! command -v wget &> /dev/null then echo -ne "\e[1mwget\e[0m was not found, please install it" @@ -11,6 +16,10 @@ elif ! command -v bc &> /dev/null then echo -ne "\e[1mbc\e[0m was not found, please install it" exit 1 +elif ! command -v xrandr &> /dev/null +then + echo -ne "\e[1mxrandr\e[0m was not found, are you using X.Org?" + exit 1 fi file=/tmp/$location