Choose style:

Author Topic: One way to randomly change wallpapers  (Read 2328 times)

0 Members and 1 Guest are viewing this topic.

Offline Slim.Fatz

  • Trusted User
  • Veteran
  • *****
  • Posts: 1853
  • Karma: 478
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
One way to randomly change wallpapers
« on: June 15, 2015, 02:01:10 pm »

Hi there everyone,


If you would like to have your workspace wallpaper changed, say every two minutes or 10 minutes, to a randomly selected wallpaper in your personal wallpapers folder, there are several different ways to accomplish this. The method that I will be describing below is one possible way.



NOTE & WARNING: My method requires disabling your file manager (Nemo) from controlling your desktop. This means, for example, that you will no longer have desktop icons unless you change the script to read exactly like the script given in the first reply to this tutorial (a super-sized thank you to PCNetSpec for this script!!). Furthermore, you do not follow the steps in the other tutorial (that I have linked to below) and you do not install the program feh !! Then you can have randomly changing wallpapers and desktop icons!!


For those of you who, like me, either do not like to have desktop icons or need to disable Nemo's control of the workspace so that you can scroll from one workspace to the next using the scroll wheel of your mouse (as described in this forum tutorial), then implementing this tutorial will be your quick and easy solution to randomly changing your workspace wallpaper.

The first thing to do is to follow and implement the tutorial previously mentioned -- but only if you do not need or wish to have desktop icons!

After having done the steps in the other tutorial, you should (using Nemo) create a folder that will contain only the wallpapers that you wish to use. I have created a folder cleverly named wallpapers in my Pictures folder.  8)


I only use pictures for my wallpapers that I have scaled to be the size of my monitor, but that is not necessary for this tutorial.

Having created your new folder, place all of your cool wallpapers in your new wallpapers folder.

To display the workspace wallpapers I use the program feh which is not included in the standard Peppermint 6 installation. It might be possible to use other programs to achieve this but I like to use feh (it is quite light weight), so I will use it in this tutorial.


To install feh open a terminal with the key combination <Ctrl><Alt>t or by opening Peppermint's main menu in the panel and clicking on the entry cryptically named entry Terminal:-\


In the terminal that opens enter this:


Code: [Select]
sudo apt-get install feh


and press the ENTER key. Enter your password as requested, etc. After feh has been installed you can close the terminal window by pressing the key combination <Ctrl>d or by clicking on the close window button.


I also have created a folder called Scripts within my home folder and that I use for all of my personally written script files (this is not needed to use this tutorial, but it is how I keep things organized in my computer -- for the rest of this tutorial I will be assuming that you also have done this).


Open this Scripts folder with Nemo and then press the F4 key to get a command line session going there. In the terminal that opens type in the following:


Code: [Select]
gedit ./cronjob-wallpaper.txt


and press the ENTER key. Type (or even better: copy and paste) the following information into the file you just opened in the editor:


Code: [Select]
*/2 * * * * DISPLAY=:0.0 /home/<your_username>/Scripts/random-wallpaper.sh


NOTE: do not literally type <your_username> !!! Replace that by YOUR ACTUAL USERNAME -- which might be tom or geeko or whatever -- although whatever is a rather dorky username...  ::)


Save the file and close the text editor. So what does the single line in this file mean? It contains the directions for a program called cron that your Peppermint 6 installation already has installed. This program can be instructed to do something at a particular time or time interval. In this case we tell it to call a script (which we will write shortly and save in your Scripts folder) named


Code: [Select]
random-wallpaper.sh


every 2 minutes. The script is what actually changes the workspace wallpaper by running the program feh and passing it the path to a randomly selected wallpaper. If you prefer changing the wallpaper every 5 minutes, then change the number 2 in the file


Code: [Select]
cronjob-wallpaper.txt


to the number 5. Those interested in more details about the exact format for instructions given to cron can find that information elsewhere (believe it or not, I am trying my best to keep this tutorial relatively short  :o ).

If anything causes trouble (i.e. no wallpaper changes) it might be this part of the entry:

Code: [Select]
DISPLAY=:0.0

but until now I have not had problems with this on the computers where I use this tutorial's method to randomly change the wallpaper. So try it. It will not break anything if it is incorrect for your computer -- just no wallpaper will get changed.

Next, we will write the script that actually randomly selects and changes the wallpaper. To do this open a terminal in the Scripts folder (if it is not still open) and type this into the terminal:


Code: [Select]
gedit random-wallpaper.sh


and press the ENTER key. In the editor type in the following (or even better: copy it from here and paste into the editor):

Code: [Select]
#!/bin/bash

# Script to randomly set desktop wallpaper
# from files in a specified directory.

# Directory containing the pictures.
WALLPAPERS="/home/<your_username>/Pictures/wallpapers"

ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[*]}
SHOW=$(( $RANDOM % $RANGE ))

# Command to set background image (wallpaper).
feh --bg-scale $WALLPAPERS/${ALIST[$SHOW]}

(NOTE: for those wishing to keep their desktop icons, etc. do not use the script as given above but copy and paste the script found in the first reply to this tutorial that was written by PCNetSpec!! You can then follow the remaining steps of this tutorial)

Again, be sure to REPLACE <your_username> with whatever and, if your wallpapers folder is located in a different place, correct the path to it in that same line.

Save this file and close the editor and the terminal. In Nemo right-click on the file you just created

Code: [Select]
random-wallpaper.sh

and, in the pop-up list that appears, click on the entry at the bottom named Properties. In the Properties window that opens, click on the tab at the top named Permissions. Put a check-mark in each of the three checkboxes named Execute and then click on the button Close (in the lower right corner of the window).

Now all we need to do is give cron its instructions that we have stored in the file

Code: [Select]
cronjob-wallpaper.txt

To do this, navigate to the Scripts folder with Nemo and then press the F4 key to open a terminal in that folder. Now type the following into the terminal:

Code: [Select]
crontab cronjob-wallpaper.txt

and press the ENTER key. Nothing seems to have happened but the command crontab has given cron the instructions. To be sure type this into the same terminal:

Code: [Select]
crontab -l

and press the ENTER key. You should see the following output:

Code: [Select]
*/2 * * * * DISPLAY=:0.0 /home/<your_username>/Scripts/random-wallpaper.sh

with your actual username, of course. If you wait for the two minutes (make it 3 to be extra sure) and nothing happens then carefully check that everything has been typed into the two files absolutely correctly! The slightest typographical error and this will most likely not work.

If you wish to stop your wallpapers from getting changed then you erase the crontab job by opening a terminal and entering this:

Code: [Select]
crontab -r

and pressing the ENTER key. The output will then look something like this:

Code: [Select]
no crontab for <your_username>

To restart the randomly changing workspace wallpapers open a terminal in your Scripts folder and type this:

Code: [Select]
crontab cronjob-wallpaper.txt

and press the ENTER key. Check that the crontab has been created with

Code: [Select]
crontab -l

So that is the end of this tutorial. I hope that everything works for you. If you get mixed up about keeping or not keeping desktop icons, just ask back here again for assistance.

As always, comments and suggestions are appreciated.

Regards,

-- Slim
« Last Edit: June 27, 2015, 07:04:29 am by Slim.Fatz »
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Online PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26468
  • Karma: 2864
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: One way to randomly change wallpapers
« Reply #1 on: June 15, 2015, 08:11:50 pm »
You're at it again aint ya ;) .. this is liable to cause people all sort of problems if they're using the default Peppermint 6 setup and don't fully grasp that this is going to kill their desktop icons

This tutorial should carry a BIG RED WARNING that it requires you to loose the ability to save ANYTHING to your desktop and have it display

feh does NOT work with nemo controlling the desktop

If you want it to work with the default environment and not break the desktop .. make the script read:
Code: [Select]
#!/bin/bash

# Script to randomly set desktop wallpaper
# from files in a specified directory.

# Directory containing the pictures.
WALLPAPERS="/home/<username>/Pictures/Wallpapers"

gsettings set org.gnome.desktop.background picture-uri "file:///$(find $WALLPAPERS -type f | shuf -n1)"

exit 0
and don't disable the desktop icons in dconf-editor

@Slim.Fatz

Do you think a "openbox tutorials" sub forum would be handy for these ? .. I'm just worried they're going to confuse some people.
« Last Edit: October 11, 2015, 05:08:16 pm by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline Slim.Fatz

  • Trusted User
  • Veteran
  • *****
  • Posts: 1853
  • Karma: 478
  • Where's the mouse?
    • View Profile
  • Peppermint version(s): Peppermint 7, 8.5 & 10 - 64bit
Re: One way to randomly change wallpapers
« Reply #2 on: June 15, 2015, 11:37:26 pm »
@PCNetSpec,


Either a sub-forum or maybe I should just begin the title with OPENBOX: blah, blah ? Your call. I did mention in both tutorials the loss of desktop icons (in red even).


But I get your point.  ;)  Or I can simply modify the tutorial, changing the script by adding your two lines and adjusting the text accordingly.


Let me know,

EDIT: modified the tutorial by adding warning notes and instructions for using the script that you developed.

-- Slim
« Last Edit: June 16, 2015, 06:33:14 am by Slim.Fatz »
"Life first -- Peppermint a close 2nd!" -- Zeb

Tread lightly: Fluxbox, JWM, i3, Openbox, awesome

Online PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26468
  • Karma: 2864
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: One way to randomly change wallpapers
« Reply #3 on: June 16, 2015, 05:13:03 am »
What I'd really like is BOTH tutorials, but with some way to clearly delineate them .. and I need to keep up ;)

I think my main concern is you seem to be getting your tutorials out FIRST, and as their subject matter is so interesting and useful (and without something to link to and say "if you wanna keep your desktop icons go here") I worry people will attempt them even with a warning then find themselves in a hole they don't fully understand.
(or maybe I'm just jealous :) )

it would be nice if I were quicker, and we could find a way to say follow path "A" if you wanna keep your desktop controlled by nemo, and follow path "B" if you're going in a more openbox direction.

That said, and the more I think about it, I shouldn't be denying people the OPTION to experiment because of MY fears .. and I should really give people more credit, so ignore me and please continue with your excellently written tutorials my  mate, and I'll try to keep up ;)
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec