I have a script that updates my desktop background every day with the NASA APOD. Since upgrading to 11.10, that script stopped working, presumably because I'm using gconftool-2 to actually update the desktop background. Is there a new way to do this under Unity?
|
|
||||
|
|
|
Both Unity and Gnome Shell (Gnome 3) use GSettings now instead of GConf. So in Unity and Gnome Shell you can use the command-line tool You can get the current URI of the background image as follows:
And set the background URI as follows (which will immediately update your desktop background):
Notice that you must prepend the URI with "file://" for this to work (unlike with In order to make your script work with both Gnome 2 and Shell/Unity, you can let it do a Gnome version check first:
That will return the version of Gnome. If the version number starts with 3, then |
|||||||||||||||||||||
|
IntroductionThis answer is an edit of the original answer. As I've progressed in my Ubuntu and Linux studies, I've discovered a variety of approaches and deepened my understanding of how setting a background works in Ubuntu. This answer is my attempt to document as best as possible what I've learned thus far, and is done in hopes that this material can be useful for others. The important part is that to set background for Unity desktop from command line, you can use
Setting background in Unity vs bare X desktopThe way Unity works is such that there is bare X desktop below, and above there is Unity's desktop window (which in fact is a special instance of Nautilus's window , the default file manager of Ubuntu ). Thus, when you call
that sets background for that special Nautilus window. When you disable desktop icons with
that will kill the Nautilus desktop and show you bare-bones X desktop. For the bare-bone X desktop you can use
There's also GUI alternative to that, Disecting the gsettings commandWhat exactly does URI, that Scripting with gsettingsOf course, writing out the command each time is tedious and one can use a little bit of scripting magic. For instance, here's what I have set in my
This function can be called with absolute path such as
or with relative path from current working directory
It also performs a check if file exists and resolves symlinks. This can be used in a shell script or as standalone function for daily use. Of course, this is not the only way. Python has an API for Gio ( which is the main library behind
Of course, same rules for scripts apply here too: ensure it is made executable with |
||||
|
|
|
Also you can use this:
|
||||
|
|
|
Thanks to Serrano's awesome answer, I was able to write this script which I use as part of my new machine setup scripts to set a black background:
|
||||
|
|
|
This code randomly changes the wallpaper from a given directory.
Save this script and edit your with the command "crontab -e" (it launches an editor where you put this line at the end of the file):
|
|||||
|
protected by Community♦ Aug 23 '16 at 6:55
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?