Last active
November 19, 2019 19:16
-
-
Save alex700/5f27b85d0c5b401b1dc19f167c61bbc8 to your computer and use it in GitHub Desktop.
KDE5 - Set National Geographic Picture of a Day to Desktop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script downloads photo of the day from nationalgeographic.com and set it as desktop wallpaper. | |
# Applicable for Ubuntu KDE 18.04 | |
# Permission to copy, modify, and distribute is granted under GPLv3 | |
# Last Revised 7 Mar 2019 | |
# | |
# Initial installation: | |
# Place the script into /usr/local/bin/ng_image_skin | |
# Run it to pull image and create symlink to it which will be lcocated at ~/Picture/Wallpapers/wp_image | |
# Set desktop image manually that pointed to ~/Picture/Wallpapers/wp_image | |
# Add the script to autoload list. | |
# Next time after system boot new image will be authomatically downloaded and wp_image symlink will be pointed to new image. | |
# Launch following command in console to debug plasmashell script: | |
# qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.showInteractiveConsole | |
# Define initial vars | |
# Image Source Page | |
IMG_SOURCE='https://www.nationalgeographic.com/photography/photo-of-the-day/'; | |
#Symlink path | |
SYMLINK_PATH="${HOME}/Pictures/Wallpapers/wp_image"; | |
SYMLINK_DIR=$(dirname $SYMLINK_PATH); | |
####################### | |
function get_page { | |
imgUrl="$(wget -qO- $IMG_SOURCE | | |
grep -Eoi '<meta property=\"og:image\" content=\"[^>]+>' | | |
grep -Eo 'content=\"[^\\"]+\"' | | |
grep -Eo '(http|https)://[^\"]+')"; | |
imgUrl=${imgUrl%/} | |
} | |
# Set new desktop img path | |
function reset_desktop_img() { | |
img_file_path=$1; | |
## For gnome | |
# gsettings set org.gnome.desktop.background picture-uri "file://${SYMLINK_PATH}" | |
## For kde | |
dbus-send --session --dest=org.kde.plasmashell --type=method_call /PlasmaShell org.kde.PlasmaShell.evaluateScript "string: | |
var Desktops = desktops(); | |
for (i=0;i<Desktops.length;i++) { | |
d = Desktops[i]; | |
d.wallpaperPlugin = 'org.kde.image'; | |
d.currentConfigGroup = Array('Wallpaper', | |
'org.kde.image', | |
'General'); | |
d.writeConfig('Image', 'file://${img_file_path}'); | |
}" > /dev/null 2>&1; | |
} | |
# Check for network | |
while [ -z "`curl -s --head https://google.com/ | head -n 1 | grep 'HTTP'`" ] | |
do | |
echo "Network is down. Waiting for connection." | |
sleep 60 | |
done | |
####################### | |
# Getting the image URL | |
get_page; | |
if [ -n "$imgUrl" ] | |
then | |
CURR_DATE=`date +%Y-%m-%d`; | |
IMAGE_FILENAME=`echo $CURR_DATE$USER | md5sum | cut -d ' ' -f 1`".jpg"; | |
img_file_path="${SYMLINK_DIR}/${IMAGE_FILENAME}"; | |
wget --quiet -O $img_file_path $imgUrl; | |
echo "Wallpaper downloaded successfully and saved as ${img_file_path}" | |
reset_desktop_img "$img_file_path"; | |
else | |
echo "Wallpaper not found" | |
fi | |
####################### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment