3

I tried this code:

import os
os.system("gsettings set org.gnome.desktop.background picture-uri file:///home/user/Pictures/wallpapers/X")

where user is my name and X is the picture.

But instead of changing the background to the given picture, it set the default Ubuntu wallpaper.

What am I doing wrong?

Michael Laszlo
  • 12,009
  • 2
  • 29
  • 47
Ali Faki
  • 3,928
  • 3
  • 17
  • 25

4 Answers4

7

First of all, make sure the file path is correct. Execute this line in a terminal:

ls /home/user/Pictures/wallpapers/X

Did the file get listed? If so, move on to the next step.

Make sure that you know where the gsettings command is. In the terminal, run:

which gsettings

That should get you the full path to gsettings. If nothing is displayed, the directory containing gsettings isn't in your $PATH variable.

Let's say the path is /usr/bin/gsettings. Try to execute this in a terminal:

/usr/bin/gsettings set org.gnome.desktop.background picture-uri /home/user/Pictures/wallpapers/X

If it works, pass the same string to os.system():

import os
os.system("/usr/bin/gsettings set org.gnome.desktop.background picture-uri /home/user/Pictures/wallpapers/X")
Community
  • 1
  • 1
Michael Laszlo
  • 12,009
  • 2
  • 29
  • 47
1

Try this:

import os
os.system("gsettings set org.gnome.desktop.background picture-uri file:/home/user/Pictures/wallpapers/picture_name")
afwanwh
  • 176
  • 1
  • 8
1

Try this one:

import subprocess
subprocess.Popen("DISPLAY=:0 GSETTINGS_BACKEND=dconf /usr/bin/gsettings set org.gnome.desktop.background picture-uri file://{0}".format(picture_path), shell=True)

it will works even when you use it in cron. I'v written a script that download bing images and then set as wallpaper.

also you could try the following commands:

feh --bg-fill picture_path
hsetroot  -extend  picture_path
lord63. j
  • 4,500
  • 2
  • 22
  • 30
1

To set a specific wallpaper, the command is:

gsettings set org.gnome.desktop.background picture-uri 'file:///home/user/Pictures/wallpapers/apple.jpg'

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

gsettings get org.gnome.desktop.background picture-uri
Rutul Raval
  • 313
  • 2
  • 10