#!/bin/sh # Triggered by Right # as defined in [org/gnome/settings-daemon/plugins/media-keys] # in ~/.config/gnome-settings/key-bindings.ini # # This script ensures "Night Light" is forced on # if it was not yet on by schedule # and makes the screen a bit warmer than it currently is # # The default warmth is restored at login by ~/.local/bin/restore-gnome set -eu # GNOME's GUI lets one choose between 1700 and 4700 only, # and 6500 is the point where no color correction is applied at all # while 1000 is the absolute minimum supported by the OS _MIN_TEMPERATURE=1200 _MAX_TEMPERATURE=4700 notify() { ID_FILE="${XDG_RUNTIME_DIR}/night-light-notification-id" _id=$(cat "$ID_FILE" 2>/dev/null || true) if [ -n "$_id" ]; then notify-send -p -t 5000 --replace-id="$_id" "Night Light" "$1" > "$ID_FILE" || rm -f "$ID_FILE" else notify-send -p -t 5000 "Night Light" "$1" > "$ID_FILE" || rm -f "$ID_FILE" fi } Schema=org.gnome.settings-daemon.plugins.color active=$(gdbus call --session \ --dest org.gnome.SettingsDaemon.Color \ --object-path /org/gnome/SettingsDaemon/Color \ --method org.freedesktop.DBus.Properties.Get \ org.gnome.SettingsDaemon.Color NightLightActive) current=$(gsettings get $Schema night-light-temperature | awk '{print $2}') # 500 = (4700 - 1700 + 500) / 7 # => Seven steps spanning more than the range in the GUI, # mainly because we want to allow a bit more warmth (i.e., +500) new=$((current - 500)) if [ "$new" -lt $_MIN_TEMPERATURE ]; then new=$_MIN_TEMPERATURE fi gsettings set $Schema night-light-temperature "uint32 $new" # Force "Night Light" on, saving a n call, # with the same settings as in ~/.local/bin/night-light-toggle-schedule if [ "$active" = "(,)" ]; then gsettings set $Schema night-light-enabled true gsettings set $Schema night-light-schedule-automatic false gsettings set $Schema night-light-schedule-from 0.0 gsettings set $Schema night-light-schedule-to 24.0 fi if [ "$current" -le $_MIN_TEMPERATURE ]; then if [ "$active" = "(,)" ]; then notify "is now forced on and already as warm as it gets (${_MIN_TEMPERATURE}K)" else notify "is already as warm as it gets (${_MIN_TEMPERATURE}K)" fi else if [ "$active" = "(,)" ]; then notify "is now forced on at ${new}K" fi fi