tags:

views:

327

answers:

2

Hi,

for my script in bash, I'd like to start conky if it's not running and pick a random wallpaper

#! /bin/bash
## dependances : randomize-lines

# otherwise wont work with cron
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

# random background
pathToImage="$HOME/Images/wallpaper/"
img="`find $pathToImage -name \*.jpg | rl | tail -n 1`"
/usr/bin/gconftool -t str -s /desktop/gnome/background/picture_filename $img

# test if conky is running
if ps ax | grep -v grep | grep conky > /dev/null
then
    echo "conky running"
else
    echo "conky is not running"
    conky
fi

if I try to run the script within a terminal

$ ~/script/wallpaper/random-background.sh 
conky is not running
Conky: can't open display: 0

if I put the test before the DISPLAY=0, it'll works in a terminal but not with cron

thank you

+2  A: 

I think that should be

export DISPLAY=:0

but that won't work for

~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-$DISPLAY

but you could change that to

~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
Puppe
great ! it works. Can you explain what it does because I found this block on a forum but I don't understand what it does
Martin Trigaux
It exports each line that isn't a comment in the file ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0 and it's used "to find the D-Bus session bus". My guess is that conky needs a dbus session to update the background image.
Puppe
+1  A: 

You missed a ":":

export DISPLAY=:0
Aaron Digulla