-
Notifications
You must be signed in to change notification settings - Fork 53
/
awesome-background-changer
executable file
·53 lines (41 loc) · 1.22 KB
/
awesome-background-changer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
WALLPAPER_DIR=$HOME/Pictures/wallpapers
SCRIPT_NAME=$(basename $0)
setWallpaper() {
local image=$1
gconftool-2 --type string --set /desktop/gnome/background/picture_filename "$image"
gconftool-2 --type string --set /desktop/gnome/background/picture_options zoom
gconftool-2 --type bool --set /desktop/gnome/background/draw_background true
}
# set wallpaper and exit if filenamae supplied
if [[ "$1" ]]; then
if [[ -f "$1" ]]; then
cd $(dirname $1)
image=$PWD/$(basename $1)
elif [[ -f "$WALLPAPER_DIR/$1" ]]; then
image=$WALLPAPER_DIR/$1
else
printf "File not found: %s\n" "$1"
exit 1
fi
printf "Setting wallpaper to %s\n" "$image"
setWallpaper "$image"
exit 0
fi
# Ensure only THIS instance of the script is running
for pid in $(pidof -xo $$ $SCRIPT_NAME 2>/dev/null); do
other_pids+=" $(pstree -Apl $pid | sed -r 's/[^)]*\(//g; s/\)/ /g' | xargs echo)"
done
[[ $other_pids ]] && kill $other_pids 2>/dev/null
cd $WALLPAPER_DIR
# Main loop
while sleep ${delay:-0}; do
wallpapers=( * )
while [[ $choice == $last ]]; do
index=$(( RANDOM % ${#wallpapers[@]} ))
choice=${wallpapers[$index]}
done
last=$choice
setWallpaper "$WALLPAPER_DIR/$choice"
delay=$(( 3600 - $(date '+60*%M+%S' | bc) ))
done