Sigh. cron can be a real pain sometimes. I've modified the script:
#!/bin/bash
/bin/date >> /tmp/test1 # TO CHECK THE CRON JOB IS RUNNING
Dir="/home/XXX/images/wallpapers"
if [ ! -d "$Dir" ]; then
echo "$Dir does not exist"
exit 1
fi
SetBG () {
TotalFiles=$( ls -1 "$Dir" | grep jpg | wc -l )
RandomNumber=$(( $RANDOM % $TotalFiles ))
test ! $RandomNumber = 0 || RandomNumber=1
RandomFile="$( ls -1 $Dir | head -n $RandomNumber | tail -n 1)"
echo "$Dir"/"$RandomFile" >> /tmp/test1 # TO CHECK
/usr/bin/nitrogen --set-scaled "$Dir"/"$RandomFile"
}
SetBG
This is saved as ~/images/wallpapers/random.sh and is chmod to 744. If I run the script on it's own, the wallpaper changes.
I setup a new cron job:
* * * * * /home/XXX/images/wallpapers/random.sh
And then tail the /tmp/test1 file. Every minute, the date and the full path and filename are appended to the file, so the script is running every minute. I've even inserted the path for nitrogen, but still the wallpaper will not change every minute.
Setting the wallpaper manually to "1.jpg" and then hard-coding the script (commenting out the existing nitrogen line and adding a new one) to set it to "2.jpg" also does not work. Adding the "--save" parameter to nitrogen also does not work. Clearly there is a trick to using nitrogen in cron...?
Last edited by SabreWolfy (2012-01-08 13:35:23)