-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamic-wallpaper-creator.sh
executable file
·258 lines (228 loc) · 5.58 KB
/
dynamic-wallpaper-creator.sh
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#/bin/bash
# Input name and create XML file
read -p "Enter the name for .xml file: " name
touch $name.xml
# Directory of the wallpapers
read -p "Path to wallpapers (e.g. /usr/share/backgrounds/pop/): " path
firstfile=$(ls $path| head -1)
# Initialize the XML file
cat >> $name.xml << EOL
<background>
<starttime>
<year>2020</year>
<month>04</month>
<day>01</day>
<hour>00</hour>
<minute>00</minute>
<second>00</second>
</starttime>
<!-- This animation will start at midnight. -->
EOL
echo ""
echo "How long should each picture display for? (Enter corresponding number)"
echo ""
echo "1) 15 minutes | 2) 30 minutes | 3) 60 minutes | 4) 120 minutes"
echo ""
# Text at prompt when entering number
PS3="Enter number: "
# count to ensure $firstfile does not get added, as it was added in the initialization
count=0
# 4 inputs
select time in fifteen thirty hour twohours
do
case $time in
fifteen)
# Adding the first file
# Not indented since intents appear in text file
cat >> $name.xml << EOL
<static>
<duration>895.0</duration>
<file>$path$firstfile</file>
</static>
<transition>
<duration>5.0</duration>
<from>$path$firstfile</from>
EOL
# All files in current directory
FILES=$path*
for f in $FILES
do
# Check if file is a .jpg, .jpeg, or .png and $f isn't the first file
if [[ ${f: -3} = "jpg" ]] || [[ ${f: -4} = "jpeg" ]] || [[ ${f: -3} = "png" ]] && [[ count -gt 0 ]]
then
cat >> $name.xml << EOL
<to>$f</to>
</transition>
<static>
<duration>895.0</duration>
<file>$f</file>
</static>
<transition>
<duration>5.0</duration>
<from>$f</from>
EOL
fi
((count+=1))
done
cat >> $name.xml << EOL
<to>$path$firstfile</to>
</transition>
</background>
EOL
break
;;
thirty)
# Adding the first file
# Not indented since intents appear in text file
cat >> $name.xml << EOL
<static>
<duration>1795.0</duration>
<file>$path$firstfile</file>
</static>
<transition>
<duration>5.0</duration>
<from>$path$firstfile</from>
EOL
# All files in current directory
FILES=$path*
for f in $FILES
do
# Check if file is a .jpg, .jpeg, or .png and $f isn't the first file
if [[ ${f: -3} = "jpg" ]] || [[ ${f: -4} = "jpeg" ]] || [[ ${f: -3} = "png" ]] && [[ count -gt 0 ]]
then
cat >> $name.xml << EOL
<to>$f</to>
</transition>
<static>
<duration>1795.0</duration>
<file>$f</file>
</static>
<transition>
<duration>5.0</duration>
<from>$f</from>
EOL
fi
((count+=1))
done
cat >> $name.xml << EOL
<to>$path$firstfile</to>
</transition>
</background>
EOL
break
;;
hour)
# Adding the first file
# Not indented since intents appear in text file
cat >> $name.xml << EOL
<static>
<duration>3595.0</duration>
<file>$path$firstfile</file>
</static>
<transition>
<duration>5.0</duration>
<from>$path$firstfile</from>
EOL
# All files in current directory
FILES=$path*
for f in $FILES
do
# Check if file is a .jpg, .jpeg, or .png and $f isn't the first file
if [[ ${f: -3} = "jpg" ]] || [[ ${f: -4} = "jpeg" ]] || [[ ${f: -3} = "png" ]] && [[ count -gt 0 ]]
then
cat >> $name.xml << EOL
<to>$f</to>
</transition>
<static>
<duration>3595.0</duration>
<file>$f</file>
</static>
<transition>
<duration>5.0</duration>
<from>$f</from>
EOL
fi
((count+=1))
done
cat >> $name.xml << EOL
<to>$path$firstfile</to>
</transition>
</background>
EOL
break
;;
twohours)
# Adding the first file
# Not indented since intents appear in text file
cat >> $name.xml << EOL
<static>
<duration>7195.0</duration>
<file>$path$firstfile</file>
</static>
<transition>
<duration>5.0</duration>
<from>$path$firstfile</from>
EOL
# All files in wallpaper directory
FILES=$path*
for f in $FILES
do
# Check if file is a .jpg, .jpeg, or .png and $f isn't the first file
if [[ ${f: -3} = "jpg" ]] || [[ ${f: -4} = "jpeg" ]] || [[ ${f: -3} = "png" ]] && [[ count -gt 0 ]]
then
cat >> $name.xml << EOL
<to>$f</to>
</transition>
<static>
<duration>7195.0</duration>
<file>$f</file>
</static>
<transition>
<duration>5.0</duration>
<from>$f</from>
EOL
fi
((count+=1))
done
cat >> $name.xml << EOL
<to>$path$firstfile</to>
</transition>
</background>
EOL
break
;;
*)
echo "Please enter a valid answer"
;;
esac
done
# Move XML file to wallpaper directory
echo ""
echo "XML file will be moved to specified directory entered earlier"
sudo mv $name.xml $path
echo ""
echo "XML file has been moved to the specified directory containing wallpapers"
echo ""
# Name of XML config file to allow GNOME to recognize the wallpaper animation file
read -p "Enter the name of this wallpaper animation (for use in XML file in /usr/share/gnome-background-properties): " wallname
touch $wallname.xml
cat >> $wallname.xml << EOL
<?xml version="1.0"?>
<!DOCTYPE wallpapers SYSTEM "gnome-wp-list.dtd">
<wallpapers>
<wallpaper deleted="false">
<name>$wallname</name>
<filename>$path$name.xml</filename>
<options>zoom</options>
<shade_type>solid</shade_type>
<pcolor>#000000</pcolor>
<scolor>#000000</scolor>
</wallpaper>
</wallpapers>
EOL
# Move config file to proper directory
sudo mv $wallname.xml /usr/share/gnome-background-properties/
echo ""
echo "XML file is complete, can be found in inputted wallpaper directory."
echo "Config file is in /usr/share/gnome-background-properties/"
echo "You can find wallpaper in gnome-control-center"