-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathngwallpaper.sh
executable file
·47 lines (41 loc) · 1.59 KB
/
ngwallpaper.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
#!/bin/bash
# This Script downloads National Geographic Photo of the day, and sets it as desktop background (gnome, unity)
# Copyright (C) 2012 Saman Barghi - All Rights Reserved
# Permission to copy, modify, and distribute is granted under GPLv3
# Last Revised 23 April 2017
# instead of 'cinnamon-session|gnome-session|mate-session"', 'noutilus', or 'compiz' can be used
# or the name of a process of a graphical program about that you are sure that is
# running after you log in the X session
PID=$(pgrep -o "cinnamon-sess|gnome-sess|mate-sess")
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
#check for network
while [ -z "`curl -s --head https://google.com/ | head -n 1 | grep 'HTTP/1.[01]'`" ]
do
echo "Network is down!!"
sleep 1800
done
#######################
#Change directory to where the script resides.
BASEDIR=$(dirname $0)
cd $BASEDIR
#######################
#getting the image URL
img="$(curl https://www.nationalgeographic.com/photography/photo-of-the-day -s -L | grep -oP '(?<="og:image" content=")\K[^"]*')"
#check to see if there is any wallpaper to download
if [ -n "$img" ]
then
img_base=`echo $img | awk -F/ '{print $NF}'`
img_md5=`echo -n $img_base | md5sum | cut -f1 -d" "`
img_file="$img_md5.jpg"
if [ -f "$img_file" ]
then
echo "File $img_file already exists"
else
curl "$img" > $img_file
#set the current image as wallpaper
gsettings set org.gnome.desktop.background picture-uri "file://`pwd`/${img_file}"
echo "Wallpaper downloaded successfully and saved as $img_file"
fi
else
echo "No Wallpaper today"
fi