Created
October 23, 2022 05:46
-
-
Save lostfictions/6d10b07299c6e8f5e6d3736f6c616c0b to your computer and use it in GitHub Desktop.
toggle gnome night light from shell or via keyboard shortcut
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
BUS_NAME="org.gnome.SettingsDaemon.Color" | |
OBJECT_PATH="/org/gnome/SettingsDaemon/Color" | |
TRUE="variant:boolean:true" | |
FALSE="variant:boolean:false" | |
set_disabled() { | |
dbus-send --session --dest=$BUS_NAME --print-reply $OBJECT_PATH \ | |
org.freedesktop.DBus.Properties.Set string:$BUS_NAME \ | |
string:DisabledUntilTomorrow "$1" >> /dev/null | |
} | |
get_disabled() { | |
dbus-send --session --dest=$BUS_NAME --print-reply=literal $OBJECT_PATH \ | |
org.freedesktop.DBus.Properties.Get string:$BUS_NAME \ | |
string:DisabledUntilTomorrow | awk '{print $3}' | |
} | |
status=$(get_disabled) | |
case $status in | |
true) set_disabled $FALSE ;; | |
false) set_disabled $TRUE ;; | |
*) echo "unknown result when trying to get disabled status: \"$status\"" 1>&2; exit 1 ;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment