Root/
| 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 |
| 2 | cmd="gconftool-2 -s /desktop/gnome/background/picture_filename --type string" |
| 3 | dir="$HOME/Pictures/backgrounds" |
| 4 | f="$dir/.list" |
| 5 | |
| 6 | addr=$(netstat -xl | grep -o '/tmp/dbus.*' | head -1) |
| 7 | [ -n "$addr" ] || exit 0 |
| 8 | |
| 9 | export DBUS_SESSION_BUS_ADDRESS=unix:abstract=$addr |
| 10 | |
| 11 | gen_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 | |
| 22 | eval $(tail -1 $f) |
| 23 | |
| 24 | if [ "$cur" -ge "$max" ]; then |
| 25 | gen_list |
| 26 | eval $(tail -1 $f) |
| 27 | fi |
| 28 | |
| 29 | image=/dev/null |
| 30 | while [ "$cur" -lt "$max" ] && ! [ -s "$image" ]; do |
| 31 | let cur+=1 |
| 32 | image="$(sed -ne ${cur}p $f)" |
| 33 | done |
| 34 | |
| 35 | # nothing usable found |
| 36 | if ! [ -s "$image" ]; then |
| 37 | > $f |
| 38 | exit 0 |
| 39 | fi |
| 40 | |
| 41 | $cmd "$image" |
| 42 | |
| 43 | ed -s $f <<EOF |
| 44 | $((max+1))d |
| 45 | a |
| 46 | cur=$cur max=$max |
| 47 | . |
| 48 | wq |
| 49 | EOF |
| 50 | |
