11

I've done a lot of googling but haven't been able to find a solution to my problem.

I am a teacher and I'm using Xubuntu on some student computers. I have everything locked down pretty good, but I can't figure out how to restrict users from changing the wallpaper without having to out the whole machine in Kiosk mode. I don't care if they change it during their work session, but I would like to create a crontab that resets back to the original .png at reboot.

I'm hoping for a simple cron entry but I'm willing to ease into the world of shell scripts if that's what it takes.

Any ideas?

10

In Xfce land, that's

xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set /usr/share/backgrounds/xfce/xfce-blue.jpg

(Substitute the file path you want, of course.)

xfconf-query --channel xfce4-desktop --list

lists all related properties, in case screen0/monitor0 isn't the one.

  • When I run that in the command line, it works like a charm. When I try to add it to cron though, it doesn't do anything. Any ideas? ` – John Nov 22 '13 at 4:10
  • How about enclosing the whole thing in a shell script and run the shell script using cron instead? – Chester Nov 22 '13 at 5:21
  • Created the shell script and made it executable. It runs when double clicked and I can run it in the command line. I tried adding it to cron with @reboot as the time but it doesn't seem to be working. Do I need to add something to cron other than just the path to the script? – John Nov 22 '13 at 12:28
  • @John It doesn't work in cron because cron work under root privilege and this is a user specific background. try changing the command to run as your user – kamil Feb 13 '14 at 17:06
  • 1
    For me, --property /backdrop/screen0/monitorLVDS1/workspace0/last-image did the trick. – Ilmari Karonen May 9 '15 at 19:39
9

For xfce4 in Xubuntu 14.04, use property /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image instead of /backdrop/screen0/monitor0/image-path

You also need to set DBUS_SESSION_BUS_ADDRESS environment variable like this:

PID=$(pgrep xfce4-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)

In my case I wanted to rotate the wallpaper (random image from a selected folder) once a day, but I turn-on my PC irregularly, so I solved it by running a script from cron every half-hour, but only take effect once a day.

entry in crontab (add it via crontab -e command):

0,30 * * * * /home/lucifer/scripts/rotate-wallpaper.sh

rotate-wallpaper.sh:

#!/bin/bash
wallpaperdir="/home/lucifer/Pictures/wallpapers"
datefile="/home/lucifer/.wallsw"
thisday=$( date +%j )
wallfiles=($wallpaperdir/*)
randompic=`printf "%s\n" "${wallfiles[RANDOM % ${#wallfiles[@]}]}"`
PID=$(pgrep xfce4-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)

if [ -f "$datefile" ]
then
    lastday=$( cat "$datefile" )
    if [ "$lastday" != "$thisday" ]
    then    
        date +%j > "$datefile"
        xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image --set $randompic 
    fi
else
    date +%j > "$datefile"
    xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image --set $randompic
fi

Note: -If you are using non-English system locale, the property can have a different name. The best way to find out the property name, open a terminal window, and run this command:

xfconf-query -c xfce4-desktop -m

This will turn on monitoring of xfce4-desktop properties. Now change your background manually. You should see the property name which was affected by this change in the terminal window. Use this property name if it's different from /backdrop/screen0/monitorDisplayPort-1/workspace0/last-image

1

Setting image-path has no effect at my system (XFCE 4.12, Debian buster/sid).

I use the following for setting the background image of all workspaces:

xfconf-query --channel xfce4-desktop --list | grep last-image | while read path; do
    xfconf-query --channel xfce4-desktop --property $path --set <path>
done
0

Try

gsettings set org.gnome.desktop.background picture-uri file:///your/picture/location.jpg

The file:// is required.

  • I tried it without any luck. Since I'm running XFCE, do I even have gsettings? The syntax of the command makes sense to me, but I don't know how to make it apply to Xubuntu. – John Nov 22 '13 at 1:50
0

Don't use cron. Instead use the startup script. Although you can use cron but I don't prefer it in this situation because it is user specific.

Do it this way:

sudo vi /etc/rc.local

add the following at the end of file

sudo -u YOURUSERNAME -g $( id -g YOURUSERNAME ) xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set /usr/share/backgrounds/xfce/xfce-blue.jpg

and make sure you replace YOURUSERNAME with your current user. And replace /usr/share/backgrounds/xfce/xfce-blue.jpg by the real path of the new background image and make sure your user has permission to read the image

  • 1
    Why was this downvoted? The OP requested a way that effects at reboot. Perhaps the OP needed to apply it to several users, but hasn't explicitly stated so. This answer seems okay (haven't tested it, though). So, why the downvote? – Stéphane Gourichon Oct 31 '16 at 11:10
0

to set xfce background color in bash script:

d=0; r=$d; g=$d; b=$d; \
xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace0/color1 \
-s $r -s $g -s $b -s 65535

colors:

black: d=0;
white: d=65535;
red:   r=65535; g=0; b=0;

etc.

r g b are 16bit decimal RGB components.

65535 = 255*257. 255 = 0xFF in hex.

to convert from 8bit hex color code, to 16bit decimal RGB components:

x='C31717' # dark red
r=$((16#${x:0:2} * 257))
g=$((16#${x:2:2} * 257))
b=$((16#${x:4:2} * 257))

if background color does not change, set image style to none

xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace0/image-style \
-s 0

.... and set fill style to solid

xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace0/color-style \
-s 0

to set a different color for every workspace:

xfconf-query -c xfce4-desktop \
-p /backdrop/single-workspace-mode \
-s false

i=1; # workspace id
xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace$i/image-style \
-s 0
xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace$i/color-style \
-s 0
x=0; r=$x; g=$x; b=$x; \
xfconf-query -c xfce4-desktop \
-p /backdrop/screen0/monitor0/workspace$i/color1 \
-s $r -s $g -s $b -s 65535

nuff said ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.