dotfiles/scripts/watch_screensaver.sh

39 lines
913 B
Bash
Raw Normal View History

2024-04-26 17:38:35 +00:00
#!/bin/bash
pictureURI="file://${HOME}/bgs/default.jpg"
# Check for existing instances and kill them leaving current instance running
for PID in $(pidof -o %PPID -x "${0##*/}"); do
if [ "$PID" != $$ ]; then
kill -9 "$PID"
fi
done
# set initial status
ACTIVE=false
setDefaultBg() {
gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false && gsettings set org.cinnamon.desktop.background picture-uri $pictureURI
}
# Start the main loop to monitor screensaver status changes
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'" | while read -r STATE
do
if ( ! $ACTIVE ); then
echo "$STATE"
if echo "$STATE" | grep -q "boolean true"; then
echo "setting bg"
setDefaultBg
ACTIVE=true
fi
elif echo "$STATE" | grep -q "boolean false"; then
echo "$STATE"
echo "screen unlocked"
ACTIVE=false
fi
sleep 1
done