Watch
1
0
Fork
You've already forked dotfiles
0
dotfiles/.local/bin/night-light-toggle-enabled

68 lines
2 KiB
Text
Raw Normal View History

2026-08-03 14:30:55 +02:00
#!/bin/sh
# Triggered by <Alt><Shift>n
# as defined in [org/gnome/settings-daemon/plugins/media-keys]
# in ~/.config/gnome-settings/key-bindings.ini
#
# See ~/.local/bin/night-light-toggle-schedule
# for the other half of the toggling logic
# and extensive documentation
set -eu
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
if [ "$(gsettings get $Schema night-light-enabled)" = "true" ]; then
active_before=$(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)
gsettings set $Schema night-light-enabled false
if [ "$active_before" = "(<false>,)" ]; then
notify "is now disabled, but the screen was not tinted anyways"
fi
else
gsettings set $Schema night-light-enabled true
# We could start from our default warmth, as defined
# in [org/gnome/settings-daemon/plugins/color]
# in ~/.config/gnome-settings/misc.ini
# but choose not to do that because the default
# warmth is reset anyways after a reboot
# gsettings set $Schema night-light-temperature "uint32 2200"
# Give the settings daemon a moment to recompute "NightLightActive"
sleep 0.1
active_after=$(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)
if [ "$active_after" = "(<false>,)" ]; then
notify "is now enabled, but the schedule keeps it off for now"
fi
fi