Ubuntu – How to block users from changing wallpaper (under Unity in Ubuntu 12 and 14)

12.0414.04unitywallpaper

I can't find a way to block users from changing my institutional wallpaper.
I have some PCs running Ubuntu 12.04 using Unity and others running Ubuntu 14.04 using Unity.
I need some kind of tweak/command/solution that blocks the option of changing the wallpaper in any possible way.

Please don't answer me with solutions under GNOME. These two don't work for me:
How to restrict users on changing their wallpapers?
Having trouble preventing users from changing wallpaper/settings

Best Answer

Although the suggestion below is far from "waterproof", it offers at least some "first-line" precautions against changing the wallpaper too easily.

You could make a small script to run in the background that checks every x seconds if the current wallpaper is still the wallpaper that you set in the first place.

  • The command to see (get) what is the current wallpaper:

    gsettings get org.gnome.desktop.background picture-uri
    

    If you run this in a terminal, you will get an output looking like:

    'file:///home/jacob/Thema/Bureaublad4/Frog.jpg'
    

We can make the script restore the original wallpaper if it has changed.

  • To set a specific wallpaper, the command is:

    gsettings set org.gnome.desktop.background picture-uri 'file:///home/jacob/Thema/Bureaublad4/Frog.jpg'
    

If we use these two in a python script, we could get the following (python3, 14.04):

#!/usr/bin/env python3

import time
import subprocess

set_wallpaper = "file:///home/jacob/Thema/Bureaublad4/Frog.jpg"

cmd2 = "gsettings set org.gnome.desktop.background picture-uri "+set_wallpaper
cmd1 = "gsettings get org.gnome.desktop.background picture-uri"

def check_wall():
    curr_wallpaper = subprocess.check_output(["/bin/bash", "-c", cmd1]).decode("utf-8").strip()
    if curr_wallpaper == "'"+set_wallpaper+"'":
        pass
    else:
        subprocess.Popen(["/bin/bash", "-c", cmd2])

while True:
    check_wall()
    time.sleep(10)

The only difference for 12.04 is the shebang: 12.04 does not come with python3 by default, so the shebang should be:

#!/usr/bin/env python

How to use

  • copy the script into an empty file. Change the wallpaper line (after set_wallpaper =) into the path to your wallpaper image (starting with file://, like in the example). Save it as something.py.

  • run it by the command:

    python3 /path/to/something.py
    

    or (12.04)

    python /path/to/something.py
    

If all works as you wish, add it to your startup applications: Dash > "Startup Applications" > "Add"