dot rc

Sign in or create your account | Project List | Help

dot rc Git Source Tree

Root/gnome/nautilus-scripts/background

Source at commit 6d392be2399af7e989f8e79b543c1008236a0e0c created 2 years 4 months ago.
By Luciano Rocha, generate random list of images and then use all before re-generating it
1#!/bin/bash
2cmd="gconftool-2 -s /desktop/gnome/background/picture_filename --type string"
3dir="$HOME/Pictures/backgrounds"
4f="$dir/.list"
5
6addr=$(netstat -xl | grep -o '/tmp/dbus.*' | head -1)
7[ -n "$addr" ] || exit 0
8
9export DBUS_SESSION_BUS_ADDRESS=unix:abstract=$addr
10
11gen_list()
12{
13    find "$dir" -iname '*.jpg' -o -iname '*.gif' -o -iname '*.png' |
14        shuf > $f
15    [ -s "$f" ] || exit 0
16    # number_of_lines cur_line
17    echo max=$(wc -l <$f) cur=0 >> $f
18}
19
20[ -s "$f" ] || gen_list
21
22eval $(tail -1 $f)
23
24if [ "$cur" -ge "$max" ]; then
25    gen_list
26    eval $(tail -1 $f)
27fi
28
29image=/dev/null
30while [ "$cur" -lt "$max" ] && ! [ -s "$image" ]; do
31    let cur+=1
32    image="$(sed -ne ${cur}p $f)"
33done
34
35# nothing usable found
36if ! [ -s "$image" ]; then
37    > $f
38    exit 0
39fi
40
41$cmd "$image"
42
43ed -s $f <<EOF
44$((max+1))d
45a
46cur=$cur max=$max
47.
48wq
49EOF
50

Archive Download this file

Branches:
master