scripts/randomwallpaper.sh

59 lines
1.8 KiB
Bash
Raw Permalink Normal View History

2023-08-10 21:47:21 +02:00
#!/bin/sh
2014-09-13 19:07:42 +02:00
2018-01-21 23:04:08 +01:00
echo "DISPLAY:$DISPLAY"
2023-08-10 21:47:21 +02:00
Dir="/home/n/img/wallpap/2560x1440/"
wallpaplist="/home/n/.cache/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
2023-08-10 21:47:21 +02:00
AvailableFiles=$(find ${Dir} | wc -l)
AlreadyViewedFiles=$(cat ${wallpaplist} | wc -l)
2014-09-13 19:07:42 +02:00
2023-08-10 21:47:21 +02:00
TotalFiles=$((AvailableFiles-AlreadyViewedFiles))
2014-09-13 19:07:42 +02:00
2023-08-10 21:47:21 +02:00
if [ "$TotalFiles" -lt 1 ];
2014-09-13 19:07:42 +02:00
then
echo "*** Seems we have displayed all available wallpapers; let's do the time warp...again. ***"
2023-08-10 21:47:21 +02:00
printf ""> ${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
2023-08-10 21:47:21 +02:00
RandomNumber=$(shuf --input-range=1-"$TotalFiles" --head-count=1)
test ! "$RandomNumber" = 0 || RandomNumber=1
2014-09-13 19:07:42 +02:00
2023-08-10 21:47:21 +02:00
RandomFile="$(find ${Dir} -type f -printf '%f\n' | sort | grep -w -v -F -f ${wallpaplist} | head -n "$RandomNumber" | tail -n 1)"
if [ "${RandomFile}" = "" ];
2014-09-13 19:07:42 +02:00
then
echo "*** Oops, something went wrong. erasing cache for security ***"
2023-08-10 21:47:21 +02:00
printf ""> ${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
2023-08-10 21:47:21 +02:00
export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
2014-09-13 19:07:42 +02:00
2023-08-10 21:47:21 +02:00
AlreadyViewedFiles=$(cat ${wallpaplist} | wc -l)
echo "" | /usr/bin/mail -s "New wallpaper: ${RandomFile} (${AlreadyViewedFiles}/${AvailableFiles})" ${contact}
echo "Selected File: $RandomFile, which is the ${AlreadyViewedFiles}th out of ${AvailableFiles}"
for workspace in 1 2 3 4
do
xfconf-query -c xfce4-desktop -p /backdrop/screen0/monitorDisplayPort-${workspace}/workspace0/last-image -s "${Dir%/}/${RandomFile}" 2>/dev/null
done
sleep 3h
done