#!/bin/bash ########################################### # # Get the daily picture from http://www.bonjourmadame.fr on your desktop # # Author : Magetys # Link : http://www.magetys.com # Version : 1.0.1 # Dependency : libnotify-bin # Note : Works on Gnome and Xfce # ########################################### function chkinternet { if [ `wget -q -O - google.com | grep -c "Google"` != 0 ] then echo 1 else echo 0 fi } function fixdbus { export DISPLAY=0 while read line do echo $line | grep -vqe "^#" if [ $? -eq 0 ]; then export $line; fi done < ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-$DISPLAY echo Dbus fixed OK } function resize { # Get screen size res=$(xdpyinfo | grep dimensions | awk '{print $2}') tailleX=$(echo $res | awk -F "x" '{print $1}'); tailleY=$(echo $res | awk -F "x" '{print $2}'); echo "Screen Size is X: $tailleX, Y: $tailleY" # Get image size res=$(identify -format '%w %h\n' $1) imgX=$(echo $res | awk '{print $1}') imgY=$(echo $res | awk '{print $2}') echo "Original Image Size is X: $imgX, Y: $imgY" # Calculate resize factor mult=0 div=0 # If using $tailleX and $imgX as factor scale for Y -> use it! It will perfectly fitt for X and do the best for Y if [ $tailleY -gt $((($tailleX*$imgY)/$imgX)) ]; then mult=$tailleX div=$imgX else mult=$tailleY div=$imgY fi res=$((($imgX*$mult)/$div))'x'$((($imgY*$mult)/$div)) echo "New size is $res" `mogrify -resize $res $1`; } # please install libnotify-bin to popup notification function notify { if [[ -e /usr/bin/notify-send ]] then notify-send "Bonjour $USER" "Je suis arrivee sur ton bureau" -i $todaywp fi } dirprefix=$HOME/Images fileprefix=$dirprefix/bonjourmadame-wp- todaywp=$fileprefix$(date +%y-%m-%d-%H-%M).jpg while [ $(chkinternet) != "1" ]; do sleep 15; done echo Internet connection OK if [[ ! -d $dirprefix ]] then echo "Creating $dirprefix"; mkdir $dirprefix; fi wget -O - http://www.bonjourmadame.fr | grep -Eo "(http://www.bonjourmadame.fr/photo/[^\"]+)|(http://[0-9]+.media.tumblr.com/tumblr[^\"]+)" | head -n 1 | wget -q -i - -O $todaywp echo Photo downloaded OK #ls $fileprefix* | sort -r | tail -n +2 | xargs rm -f if [[ -e /usr/bin/identify ]] then resize $todaywp; echo Photo Resize OK; fi fixdbus if [[ -e /usr/bin/feh ]] then DISPLAY=:0 feh --bg-center $todaywp fi if [[ -e /usr/bin/xfconf-query ]] then xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s $todaywp fi if [[ -e /usr/bin/gconftool-2 ]] then gconftool-2 --type string --set /desktop/gnome/background/picture_filename $todaywp fi notify