You are not logged in.

#1 2015-03-19 11:47:12

halcondx
Member
Registered: 2014-09-29
Posts: 4

[script] change random wallpaper

Hi guys, I made a script that changes the wallpaper randomly and never repeat it until all have  been showed without compare them.
You can change the folder Changing Dir="$HOME/Pictures/.wallpaper", it must be a folder with only images or .hiden files.
Change  feh --bg-fill "${Dir%/}/${Archivo}" if you don't use feh. and sleep for the transition time.
All tips are welcome.

#!/bin/bash

Dir="$HOME/Pictures/.wallpaper"

Totalfiles=$( find $Dir -type f \( -iname "*" ! -iname ".*" \) | wc - )
touch $Dir/.sorted.log
Tope="$( cat $Dir/.sorted.log | wc -l )"
if [ $Tope == 0 ]; then
   Reseteador
fi

Aleatorio(){
   
   rndn=$(( $RANDOM % $Tope ))

   if [ $rndn == 0 ];then
      rndn=$Tope
   fi
   RandomFile="$( cat $Dir/.sorted.log | head -n $rndn | tail -n 1)"
   Archivo=$( ls -1 $Dir | head -n $RandomFile | tail -n 1 )
}


Imprimir(){
   
   feh --bg-fill "${Dir%/}/${Archivo}"
   sed -i "$rndn d" $Dir/.sorted.log
   Tope="$( cat $Dir/.sorted.log | wc -l )"
   sleep 5m
}

Reseteador(){
   seq 1 $Totalfiles > $Dir/.sorted.log
   Tope="$( cat $Dir/.sorted.log | wc -l )"
}

while true; do

if [ $Tope == 0 ]; then
   Reseteador
fi
Aleatorio
Imprimir
done

Last edited by halcondx (2015-03-19 12:44:48)

Offline

#2 2015-03-19 12:14:00

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [script] change random wallpaper

Do not parse 'ls' http://mywiki.wooledge.org/ParsingLs

Last edited by karol (2015-03-19 12:14:47)

Offline

#3 2015-03-19 12:45:51

halcondx
Member
Registered: 2014-09-29
Posts: 4

Re: [script] change random wallpaper

Fixed

$ ls -1 | wc -l
$ find $Dir -type f \( -iname "*" ! -iname ".*" \) | wc -l

Offline

Board footer

Powered by FluxBB