Trespasser
November 11th, 2009, 05:15 PM
Hi,
I've been trying to get a wallpaper changing bash script to run in cron but for some reason, no matter what I try, I can't get it to change my background. It shows in system log that cron is running the script but still no background change. Here's the wallpaper changer script....
#############################
#!/bin/bash
export $(xargs -n 1 -0 echo </proc/$(pidof x-session-manager)/environ | grep -Z DBUS_SESSION_BUS_ADDRESS=)
# Set the path to your wallpaper directory
WALLPAPERS=/home/bobbyjean/Pictures
# Sanity check. Is wallpapers directory empty of images?
# + Build query
QUERY=""
if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
QUERY="$QUERY$WALLPAPERS/*.jpg "
fi
if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
QUERY="$QUERY$WALLPAPERS/*.JPG "
fi
# Sanity check. Does config directory exist?
if [ ! -d /home/bobbyjean/.config/rotate-wallpaper ]; then
mkdir /home/bobbyjean/.config/rotate-wallpaper
fi
# Sanity check. Does config file exist?
if [ ! -f /home/bobbyjean/.config/rotate-wallpaper/count ]; then
touch /home/bobbyjean/.config/rotate-wallpaper/count
echo "0" > /home/bobbyjean/.config/rotate-wallpaper/count
touch /home/bobbyjean/.config/rotate-wallpaper/number
echo "0" > /home/bobbyjean/.config/rotate-wallpaper/number
fi
# Count number of wallpapers
NO_OF_WALLPAPERS=0
for file in $QUERY; do
if [ ! -d "$file" ];then
NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
fi
echo "$NO_OF_WALLPAPERS" > /home/bobbyjean/.config/rotate-wallpaper/number
done
# Read in number of last wallpaper displayed, or start from 1
PREVIOUS_WALLPAPER="$(cat /home/bobbyjean/.config/rotate-wallpaper/count)"
NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
# Do we need to loop back to 1?
if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
NEW_WALLPAPER=1
CNT=1
fi
# Set wallpaper
for file in $QUERY; do
if [ $CNT = $NEW_WALLPAPER ]; then
if [ ! -d "$file" ];then
/usr/bin/gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$file"
fi
fi
CNT=$(( CNT+1 ))
done
# Save count and exit
echo "$NEW_WALLPAPER" > /home/bobbyjean/.config/rotate-wallpaper/count
exit
############################
and here is my crontab job.....
SHELL=bin/bash
*/5 * * * * DISPLAY=:0.0 /home/bobbyjean/.chgwall/rotate-wallpaper.sh
Anyone have any idea what the problem might be?
Oh yeah, if I run this script from Terminal it changes the wallpaper just fine.
Thanks for any help on this matter.
BTW, this is in Karmic Netbook Remix 9.10.
Later....
I've been trying to get a wallpaper changing bash script to run in cron but for some reason, no matter what I try, I can't get it to change my background. It shows in system log that cron is running the script but still no background change. Here's the wallpaper changer script....
#############################
#!/bin/bash
export $(xargs -n 1 -0 echo </proc/$(pidof x-session-manager)/environ | grep -Z DBUS_SESSION_BUS_ADDRESS=)
# Set the path to your wallpaper directory
WALLPAPERS=/home/bobbyjean/Pictures
# Sanity check. Is wallpapers directory empty of images?
# + Build query
QUERY=""
if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
QUERY="$QUERY$WALLPAPERS/*.jpg "
fi
if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
QUERY="$QUERY$WALLPAPERS/*.JPG "
fi
# Sanity check. Does config directory exist?
if [ ! -d /home/bobbyjean/.config/rotate-wallpaper ]; then
mkdir /home/bobbyjean/.config/rotate-wallpaper
fi
# Sanity check. Does config file exist?
if [ ! -f /home/bobbyjean/.config/rotate-wallpaper/count ]; then
touch /home/bobbyjean/.config/rotate-wallpaper/count
echo "0" > /home/bobbyjean/.config/rotate-wallpaper/count
touch /home/bobbyjean/.config/rotate-wallpaper/number
echo "0" > /home/bobbyjean/.config/rotate-wallpaper/number
fi
# Count number of wallpapers
NO_OF_WALLPAPERS=0
for file in $QUERY; do
if [ ! -d "$file" ];then
NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
fi
echo "$NO_OF_WALLPAPERS" > /home/bobbyjean/.config/rotate-wallpaper/number
done
# Read in number of last wallpaper displayed, or start from 1
PREVIOUS_WALLPAPER="$(cat /home/bobbyjean/.config/rotate-wallpaper/count)"
NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
# Do we need to loop back to 1?
if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
NEW_WALLPAPER=1
CNT=1
fi
# Set wallpaper
for file in $QUERY; do
if [ $CNT = $NEW_WALLPAPER ]; then
if [ ! -d "$file" ];then
/usr/bin/gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$file"
fi
fi
CNT=$(( CNT+1 ))
done
# Save count and exit
echo "$NEW_WALLPAPER" > /home/bobbyjean/.config/rotate-wallpaper/count
exit
############################
and here is my crontab job.....
SHELL=bin/bash
*/5 * * * * DISPLAY=:0.0 /home/bobbyjean/.chgwall/rotate-wallpaper.sh
Anyone have any idea what the problem might be?
Oh yeah, if I run this script from Terminal it changes the wallpaper just fine.
Thanks for any help on this matter.
BTW, this is in Karmic Netbook Remix 9.10.
Later....