You are not logged in.

#1 2016-05-11 22:06:20

archist
Member
Registered: 2016-05-11
Posts: 2

Simple script for change randomly wallpaper with feh

Hi everyone, im new in this forum and i want share a little script, but very useful with the community.

The Script change the wallpaper using feh, for example, is very useful for openbox, i3wm etc... the script is:

#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ] || [ "$1" == "--help" ]; then
echo "cw 0.1"
echo "changes your wallpaper every x seconds"
echo ""          
echo "Use: cw /path/of/wallpapers/directory seconds"
echo "Example: cw /home/charlie/wallpapers 120"
exit
fi

if ! [ -e "$1" ]; then
echo "El directorio $1 no existe"
exit
fi

cd $1

function comprobar() {
num=1
for x in *;
do
       let num=$num+1

done
}

while [ 1 ]; do
        comprobar
	var_ran=$(($RANDOM%$num))
        var_aum=1
	for y in *; do
		if [ "$var_ran" -eq "$var_aum" ]; then
			feh --bg-scale $y
			sleep $2
			break
		fi		
		
		let var_aum=$var_aum+1
	done
done

To run the script is very simple:

cw /wallpapers/folder seconds-to-change

Archist.

Offline

#2 2016-05-12 19:31:08

null
Member
Registered: 2009-05-06
Posts: 398

Re: Simple script for change randomly wallpaper with feh

Or just

#!/usr/bin/env bash
while true; do
  feh --randomize --bg-fill $1/*
  sleep $2
done

Or even better, put `feh --randomize --bg-fill <yourpath>/*` to your crontab or into a systemd timer wink

Offline

#3 2016-05-14 10:11:30

archist
Member
Registered: 2016-05-11
Posts: 2

Re: Simple script for change randomly wallpaper with feh

null wrote:

Or just

#!/usr/bin/env bash
while true; do
  feh --randomize --bg-fill $1/*
  sleep $2
done

Or even better, put `feh --randomize --bg-fill <yourpath>/*` to your crontab or into a systemd timer wink

Thanks for reply, i did not know the "randomize" option.

Offline

#4 2016-05-14 10:29:27

frostschutz
Member
Registered: 2013-11-15
Posts: 1,418

Re: Simple script for change randomly wallpaper with feh

I also have a script that randomly selects a file. It doesn't use loops, only three lines:

    # show random picture
    set -- *.png
    rnd="$RANDOM$RANDOM$RANDOM"
    file="$(eval 'echo "${'$((1 + $rnd % $#))'}"')"

But it has an `eval` in it and `set` replaces $1 $2 $3 ... with filenames so may not be everyones cup of tea. It might also break if there are just too many files to choose from.

Alternatively you can use find and shuf: (shuf randomizes much faster than sort -R)

file=$(find images/ -type f -print0 | shuf -z -n 1)

Offline

#5 2016-05-15 15:37:09

LoLei
Member
Registered: 2015-08-02
Posts: 18

Re: Simple script for change randomly wallpaper with feh

I actually like your script better then those with the randomize flag, because when you have two screens like me, randomize will put a random wallpaper on each screen.

I'd rather have the same wallpaper on each screen.

Offline

Board footer

Powered by FluxBB