Changing cinnamon’s lockscreen background

Recently I want to have a different background image on the desktop and the lock screen. With my preferred desktop environment, Cinnamon, I found that this is not planned for, how disappointing. Searching the internet pointed me to a solution using a background task. The script is contained in this repository, which is btw full of nice tricks. The script there does much more than I need (no need for slide shows etc), and also uses qdbus in a sleep loop, which is somehow overdoing imho.

It turned out that using dbus-monitor alone, but not in profile output mode, but default output mode, allows for reading and acting upon the state of the screensaver. That allowed me to greatly simplify the script to the following:

#!/bin/bash
# 
 
DESKTOP_BACKGROUND=$(gsettings get org.cinnamon.desktop.background picture-uri)
DESKTOP_SLIDESHOW=$(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled)
LOCKSCREEN_BACKGROUND="/path/to/lock/screen/background/image"
 
# 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
 
dbus-monitor --session "interface='org.cinnamon.ScreenSaver', member='ActiveChanged'" | while read -r msg
do
  # The profile mode does not contain the actual value of the state, while in
  # normal output mode the state is shown in the second line:
  #signal time=1582609490.461661 sender=:1.17859 -> destination=(null destination) serial=132 path=/org/cinnamon/ScreenSaver; interface=org.cinnamon.ScreenSaver; member=ActiveChanged
  #   boolean true
  #signal time=1582609495.138523 sender=:1.17859 -> destination=(null destination) serial=143 path=/org/cinnamon/ScreenSaver; interface=org.cinnamon.ScreenSaver; member=ActiveChanged
  #   boolean false
  case "$msg" in
    "boolean true")
      DESKTOP_BACKGROUND=$(gsettings get org.cinnamon.desktop.background picture-uri)
      DESKTOP_SLIDESHOW=$(gsettings get org.cinnamon.desktop.background.slideshow slideshow-enabled)
      gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled false
      gsettings set org.cinnamon.desktop.background picture-uri "file://$LOCKSCREEN_BACKGROUND"
      ;;
    "boolean false")
      gsettings set org.cinnamon.desktop.background picture-uri "$DESKTOP_BACKGROUND"
      gsettings set org.cinnamon.desktop.background.slideshow slideshow-enabled $DESKTOP_SLIDESHOW
      ;;
    *) ;;
  esac
done

With that simple script running in the background (best via an autostart item in ~/.config/autostart/ like the following (where the above script is located in /usr/local/bin/cinnamon-lockscreen-background.sh):

[Desktop Entry]
Type=Application
Exec=/usr/local/bin/cinnamon-lockscreen-background.sh
X-GNOME-Autostart-enabled=true
NoDisplay=false
Hidden=false
Name=cinnamon-lockscreen-background.desktop
Comment=Change lockscreen background image
X-GNOME-Autostart-Delay=30

gives me my preferred background image on both the lock screen and the main desktop. Great.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">