[Solved] Automatic wallpapers slideshow

Forum rules
Before you post please read how to get help
Post Reply
Gerapa
Level 2
Level 2
Posts: 71
Joined: Sun Dec 01, 2013 7:06 pm

[Solved] Automatic wallpapers slideshow

Post by Gerapa »

Hello all,

I did some researches to find a script that would automatically change wallpapers at regular (and if possible randomly) intervals, but I did not find anything. Can any of you advise me? I run Mate on a small computer, and would prefer to avoid having to install an external program like Variety, ...

Thanks for reading.
Last edited by Gerapa on Thu Nov 14, 2019 10:27 am, edited 1 time in total.
kreemoweet
Level 2
Level 2
Posts: 50
Joined: Sat Feb 20, 2016 12:08 am

Re: Automatic wallpapers slideshow

Post by kreemoweet »

This is the script I use in my Mint 17.3 install. I set it to start when I log in, and it runs
continuously (mostly in a sleep state) and changes the background every 2 minutes (configurable).
All the backgrounds are made to fit my monitor, and are put in the named directory. The script makes
a list of the background filenames, and every time a background is set, picks a random item from the list.

Code: Select all

#!/bin/bash
backgroundsdir="/media/NTFSDATA1/Backgrounds_1920x1080"
piclist="/home/bruce/Pictures/bgpiclist.txt"
sleep 120
ls -1 $backgroundsdir > $piclist
while true
 do
   sleep 120
   currentpic=$(shuf -n 1 $piclist)
   gsettings set org.mate.background picture-filename $backgroundsdir/$currentpic
 done

User avatar
smurphos
Level 17
Level 17
Posts: 7332
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Automatic wallpapers slideshow

Post by smurphos »

So MATE supports setting xml defined desktop slideshows as a background - see the contents of /usr/share/backgrounds/cosmos for an example. The folder shows up in the appearance module like so..

Image

But there's noting wrong with the scripted solution suggested above albeit personally I'd do away with the intermediary text file and do it like this.....

Code: Select all

#!/bin/bash
backgroundsdir="/media/NTFSDATA1/Backgrounds_1920x1080"
while true
 do
   sleep 120
   currentpic="$(find "$backgroundsdir" -iname '*.*p*g' | shuf -n1)"
   gsettings set org.mate.background picture-filename "$currentpic"
 done
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Gerapa
Level 2
Level 2
Posts: 71
Joined: Sun Dec 01, 2013 7:06 pm

Re: Automatic wallpapers slideshow

Post by Gerapa »

Thanks to you two.
Oh, I did not know Cosmos. That seems interesting. Thanks for the information. Regarding the script, thank you too, that's exactly what I was looking for.
I mark the thread as solved.
vimes666
Level 3
Level 3
Posts: 199
Joined: Tue Jan 19, 2016 6:08 pm

Re: [Solved] Automatic wallpapers slideshow

Post by vimes666 »

I made a php script to generate an xml file that you can use in the mint background facilty as mentioned by smurphos (like the cosmos thing).
Feel free to change it to your needs.

Code: Select all

#!/usr/bin/php   
<?php
##############################################################################################
# 
# This script generates a slideshow.xml file in a folder with images to be used as desktop
# background slideshow.
# 
# installation:
#   - rename the script if you do not like the name (I am using 'slidez' without .php in this
#     example)
#   - copy this file to /usr/local/bin (sudo cp slidez /usr/local/bin/slidez)
#   - make the file executable if necessary (sudo chmod +x slidez)
#
# usage:
#   - in a terminal, go to your image folder (with cd) and type slidez 
#   - right-click the desktop background and click 'change desktop background'
#   - click 'Add...'
#   - select 'All files' on the pulldown button that says 'Images' (above the open button)
#   - enter your images folder in the location field
#   - select the file slideshow.xml and click open.
#   - done
#
# Created by vimes666 @ Datasmid 2019.
#
################################################################################################

$cnt = 0;
$fileout = getcwd()."/slideshow.xml";

# Make array from LS output. We do not need error msgs. 
exec("ls -d \$PWD/*.png \$PWD/*.jpg 2>/dev/null", $result);

# No use making a slideshow if there is only 1 or no image.
if (count($result) == 0) {
   echo "No images found in ".getcwd()."\n";
   echo "Cannot make a slideshow.\n";
   exit;
}
if (count($result) == 1) {
   echo "Only 1 image found in ".getcwd()."\n";
   echo "Cannot make a slideshow.\n";
   exit;
}

# Make the slide show

# open the file
$file = fopen($fileout, "w");

# first write the startdate
heading($file);

# Process all filenames
foreach ($result as &$value) {
   echo "Processing ".$value."\n";
   if ($cnt == 0) {
      statik($file, $result, $cnt);
   } 
   else {
      transition($file, $result, $cnt);
      statik($file, $result, $cnt);
   }
   $cnt ++;
}  

# Make the last line
tail($file);
 
# Close the file
   fclose( $file );

echo "Slideshow ".$fileout." created containing ".count($result)." images.\n"; 
exit;


# Write the startdate section
function heading($file) {
   fwrite( $file, "<background>\r\n");
   fwrite( $file, "  <starttime>\r\n");
   fwrite( $file, "    <year>2000</year>\r\n");
   fwrite( $file, "    <month>01</month>\r\n");
   fwrite( $file, "    <day>01</day>\r\n");
   fwrite( $file, "    <hour>00</hour>\r\n");
   fwrite( $file, "    <hour>00</hour>\r\n");
   fwrite( $file, "    <minute>00</minute>\r\n");
   fwrite( $file, "    <second>00</second>\r\n");
   fwrite( $file, "  </starttime>\r\n");
}

# Write the static section
function statik($file, $result, $cnt) {
   fwrite( $file, "  <static>\r\n");
   fwrite( $file, "    <duration>298.0</duration>\r\n");
   fwrite( $file, "    <file>".$result[$cnt]."</file>\r\n");
   fwrite( $file, "  </static>\r\n");
} 

# Write the transition section
function transition($file, $result, $cnt) {
   fwrite( $file, "  <transition>\r\n");
   fwrite( $file, "    <duration>2.0</duration>\r\n");
   fwrite( $file, "    <from>".$result[$cnt-1]."</from>\r\n");
   fwrite( $file, "    <to>".$result[$cnt]."</to>\r\n");
   fwrite( $file, "  </transition>\r\n");
}
# Write the tail line
function tail($file) {
   fwrite( $file, "</background>\r\n");
}

?>
tenfoot
Level 6
Level 6
Posts: 1067
Joined: Sun Jun 03, 2007 4:12 am
Location: Waipapa, Bay of Islands, New Zealand

Re: [Solved] Automatic wallpapers slideshow

Post by tenfoot »

Using Linux Mint v19.2 MATE

I'm rather surprised nobody has mentioned Variety as a wallpaper changer. I have been using it for years, without any problems.

You can install it from either the Software Manger or Synaptic.
tenfoot
"Light thinks it travels faster than anything but it is wrong. No matter how fast light travels, it finds darkness always got there first, and is waiting for it." Terry Pratchett (Reaper Man)
Post Reply

Return to “MATE”