-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathbingwallpaper
executable file
·129 lines (100 loc) · 2.94 KB
/
bingwallpaper
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# author: Whizzzkid ([email protected])
# Base URL.
bing="http://www.bing.com"
# API end point.
api="/HPImageArchive.aspx?"
# Response Format (json|xml).
format="&format=js"
# For day (0=current; 1=yesterday... so on).
day="&idx=0"
# Market for image.
market="&mkt=en-US"
# API Constant (fetch how many).
const="&n=1"
# Image extension.
extn=".jpg"
# Size.
size="1920x1200"
# Collection Path.
path="$HOME/Pictures/Bing/"
# Make it run just once (useful to run as a cron)
run_once=false
while getopts "1" opt; do
case $opt in
1 )
run_once=true
;;
\? )
echo "Invalid option! usage: \"$0 -1\", to run once and exit"
exit 1
;;
esac
done
########################################################################
#### DO NOT EDIT BELOW THIS LINE #######################################
########################################################################
# Required Image Uri.
reqImg=$bing$api$format$day$market$const
while [ 1 ]
do
# Logging.
echo "Pinging Bing API..."
# Fetching API response.
apiResp=$(curl -s $reqImg)
if [ $? -gt 0 ]; then
echo "Ping failed!"
exit 1
fi
# Default image URL in case the required is not available.
defImgURL=$bing$(echo $apiResp | grep -oP "url\":\"[^\"]*" | cut -d "\"" -f 3)
# Req image url (raw).
reqImgURL=$bing$(echo $apiResp | grep -oP "urlbase\":\"[^\"]*" | cut -d "\"" -f 3)"_"$size$extn
# Image copyright.
copyright=$(echo $apiResp | grep -oP "copyright\":\"[^\"]*" | cut -d "\"" -f 3)
# Checking if reqImgURL exists.
if ! wget --quiet --spider --max-redirect 0 $reqImgURL; then
reqImgURL=$defImgURL
fi
# Logging.
echo "Bing Image of the day: $reqImgURL"
# Getting Image Name.
imgName=${reqImgURL##*/}
# Create Path Dir.
mkdir -p $path
# Saving Image to collection.
curl -L -s -o $path$imgName $reqImgURL
# Logging.
echo "Saving image to $path$imgName"
# Writing copyright.
echo "$copyright" > $path${imgName/%.jpg/.txt}
if [ "$XDG_CURRENT_DESKTOP" = "XFCE" ]
then
xres=($(echo $(xfconf-query --channel xfce4-desktop --list | grep last-image)))
for x in "${xres[@]}"
do
xfconf-query --channel xfce4-desktop --property $x --set $path$imgName
done
elif [ "$XDG_CURRENT_DESKTOP" = "i3" ]
then
feh --bg-scale $path$imgName
elif [ "$XDG_CURRENT_DESKTOP" = "MATE" ]
then
gsettings set org.mate.background picture-filename $path$imgName
# Set the wallpaper for unity, gnome3, cinnamon.
elif gsettings set org.gnome.desktop.background picture-uri "file://$path$imgName"; then
#Logging
# Set the view to zoom,
gsettings set org.gnome.desktop.background picture-options "zoom"
else
echo "$XDG_CURRENT_DESKTOP not supported."
break
fi
echo "New wallpaper set successfully for $XDG_CURRENT_DESKTOP."
# If -1 option was passed just run once
if [ $run_once == true ];then
break
fi
# Re-checks for updates every 3 hours.
sleep 10800
done