Skip to content

Instantly share code, notes, and snippets.

@nibalizer
Created June 21, 2022 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibalizer/c1ac3ebf74f6a44b4a63cce20d0b9c3c to your computer and use it in GitHub Desktop.
Save nibalizer/c1ac3ebf74f6a44b4a63cce20d0b9c3c to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script to watch for dbus events and turn off keylight when monitor screen dims
# Adapted from: https://askubuntu.com/questions/858236/how-do-i-call-dbus-code-that-monitors-when-screen-is-locked-unlocked
# TODO set it up to store previous state when it turns off and restore that state after
# Apache2
# there are a lot of utils out there to control these things, so at least attempt to be portable
export KEYLIGHT_CMD_ON="keylightctl switch -light 7F8C -brightness 3 -temperature 200 on"
export KEYLIGHT_CMD_OFF="/home/nibz/local/bin/keylightctl switch -light 7F8C off"
dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | \
(
while read event
do
if $(echo ${event} | grep -q 'boolean false'); then
echo "lights on!"
$KEYLIGHT_CMD_ON
fi
if $(echo ${event} | grep -q 'boolean true'); then
echo "lights off!"
$KEYLIGHT_CMD_OFF
fi
done
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment