scripts/randomwallpaper.sh

66 lines
2 KiB
Bash
Raw Normal View History

2014-09-13 19:07:42 +02:00
#!/bin/bash
#export DISPLAY=:0.0
2018-01-21 23:04:08 +01:00
echo "DISPLAY:$DISPLAY"
Dir="~/img/wallpap/1920x1200/"
wallpaplist="~/.wallpaplist"
contact="n@tourmentine.com"
2014-09-13 19:07:42 +02:00
if [ ! -d "$Dir" ];
then
echo "${Dir} does not exist"
exit 1
fi
if [ ! -f ${wallpaplist} ];
then
touch ${wallpaplist}
fi
while true; do
2014-09-13 19:07:42 +02:00
AvailableFiles=`ls -1 ${Dir} | wc -l`
AlreadyViewedFiles=`cat ${wallpaplist} | wc -l`
TotalFiles=`expr $AvailableFiles - $AlreadyViewedFiles`
if [ $TotalFiles -lt 1 ];
then
echo "*** Seems we have displayed all available wallpapers; let's do the time warp...again. ***"
echo ""> ${wallpaplist}
echo "" | /usr/bin/mail -s "Seems we have displayed all available wallpapers; let's do the time warp...again." ${contact}
2014-09-13 19:07:42 +02:00
TotalFiles=$AvailableFiles
fi
RandomNumber=$(( $RANDOM % $TotalFiles ))
test ! $RandomNumber = 0 || RandomNumber=1
RandomFile="$( ls -1 ${Dir} | grep -w -v -F -f ${wallpaplist} | head -n $RandomNumber | tail -n 1)"
if [[ ${RandomFile} == "" ]];
then
echo "*** Oops, something went wrong. erasing cache for security ***"
echo ""> ${wallpaplist}
echo "" | /usr/bin/mail -s "Oops, something went wrong. erasing cache for security" ${contact}
2014-09-13 19:07:42 +02:00
exit 1
else
echo "${RandomFile}" >> ${wallpaplist}
fi
if [ -z "${DBUS_SESSION_BUS_ADDRESS}" ] ; then
. ${HOME}/.dbus/session-bus/`ls -rt ${HOME}/.dbus/session-bus/ | tail -1`
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
fi
#echo ${DBUS_SESSION_BUS_ADDRESS}
2014-09-13 19:07:42 +02:00
echo "" | /usr/bin/mail -s "New wallpaper: ${RandomFile}" ${contact}
echo "Selected File: $RandomFile"
2014-09-13 19:07:42 +02:00
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitor0/image-path -s "${Dir%/}/${RandomFile}"
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitor0/last-image -s "${Dir%/}/${RandomFile}"
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitorVGA1/workspace0/last-image -s "${Dir%/}/${RandomFile}"
xfconf-query -c xfce4-desktop -v -p /backdrop/screen0/monitor0/workspace0/last-image -s "${Dir%/}/${RandomFile}"
pkill gkrellm && gkrellm &
# 3 hours
sleep 10800
done