-
Notifications
You must be signed in to change notification settings - Fork 0
/
earthwallpaperlive
executable file
·96 lines (86 loc) · 3.35 KB
/
earthwallpaperlive
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
set -xv
## earthwallpaperlive - Set desktop background to earth image
##
## Usage: earthwallpaperlive [-p] [<projection>]
## -p: pause for 10 seconds to settle the net connection
## <projection> is one of: mercator (default), peters, rectangular, random
##
## Required: wget; pgrep (procps); rm, mv, sleep, sync (coreutils);
## [for peters projection] convert (imagemagick); [app for setting wallpaper]
##
## A cron job could be setup (crontab -e) to run every hour automatically:
## * 44 * * * /PATH/TO/earthwallpaperlive
## The script has to have execute permissiom then:
## chmod +x /PATH/TO/earthwallpaperlive
Help(){
cat <<-EOH
earthwallpaperlive - Set desktop background to earth image
Usage: earthwallpaperlive [-h|--help] | [-p] [<projection>]
-p: pause for 10 seconds to settle the net connection
<projection> is one of: mercator (default), peters, rectangular, random
-h/--help: display this help text
EOH
exit 0
}
Wallpaper(){ # $1: imagefile
if pgrep -f mate-settings-daemon >/dev/null
then DISPLAY=':0.0' gsettings set org.mate.background picture-filename "$1"
xcaja=$(xwininfo -name x-caja-desktop)
xid=$(grep '^xwininfo' <<<$xcaja |cut -d' ' -f4)
xdotool windowunmap $xid; sleep 1; xdotool windowmap $xid
elif pgrep -f cinnamon-session >/dev/null
then gsettings set org.cinnamon.desktop.background picture-uri "file://$1"
elif pgrep -f gnome-session >/dev/null
then gsettings set org.gnome.desktop.background picture-uri "file://$1"
elif pgrep -f xfce4-session >/dev/null
then
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/image-path --set "$1" 2>/dev/null
xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image --set "$1" 2>/dev/null
elif type -p feh >/dev/null
then feh --bg-fill "$1"
elif type -p nitrogen >/dev/null
then nitrogen --set-zoom-fill "$1"
elif type -p bgs >/dev/null
then bgs "$1"
elif type -p hsetroot >/dev/null
then hsetroot -fill "$1"
elif type -p habak >/dev/null
then habak -mS "$1"
elif [[ $(uname) = "Darwin" ]]
then osascript -e "Tell 'Finder' to set desktop picture to POSIX file '${1/#\~/$HOME}'"
else # trying GNOME..?
gsettings set org.gnome.desktop.background picture-uri "file://$1"
fi
}
Main(){
[[ $1 = -h || $1 = --help ]] && Help
! type -p wget >/dev/null && echo "ERROR: wget required" && return 1
pause=0
[[ $1 = "-p" ]] && pause=1 && shift
[[ $1 ]] && proj=$1 && shift
[[ $1 = "-p" ]] && pause=1 && shift
[[ $1 ]] && echo "ERROR: surplus arguments '$*'" && return 2
# default is the first element, random the last
p=(mercator peters rectangular random)
printf '%s\n' ${p[@]} |grep -q "^$proj$" || proj=$p ## if not found: default
[[ $proj = random ]] && proj=${p[$((RANDOM%(${#p[@]}-1)))]}
pictmp=/tmp/earthwallpaperlive.jpg
pic=/home/pp/earthwallpaperlive.jpg
# available dimensions: 1600x770/887 1280x616 1024x493
width=1600
((pause)) && sleep 10
wget -qpO "$pictmp" -w 10 --connect-timeout=20 "https://static.die.net/earth/$proj/$width.jpg"
# If temporarily unavailable, skip
(($?==8)) && return 1
[[ -s $pictmp ]] && cp "$pictmp" "$pic" || return 2
sleep 1
sync
sleep 1
# For peters cut 26 pixels from top and bottom
[[ $proj = peters ]] && type -p convert >/dev/null &&
convert "$pic" +repage -trim -fuzz 90% +repage "$pic"
Wallpaper "$pic" >/dev/null
return 0
}
Main "$@"