It is currently Mon May 21, 2018 4:24 am

change desktop backgrounds

All times are UTC - 6 hours

Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sun Dec 07, 2008 5:51 pm   

Joined: Thu Dec 01, 2005 4:51 pm
Posts: 4
Location: Montana
As most of you know, I'm pretty ignorant about scripts, etc. but in this thread on USALUG Clik ;) masinick and I discussed if there were a possibility of somehow making your desktop change regularly and automagically. I know I'll have to get serious about learning bashscripting if it is possible, but first I'd like to know if it's possible. Right now, I have a background that comes from the astronomy website, and I have a couple more that I'd like to use as well ..... the upshot of this is , I'd like to put a few (8 or 10) of those astronomy pics into the proper file (/usr/share/xfce4/backdrops), and come up with a script that would change from one to the other every 3 or 4 days, week, month, etc., kinda like a screensaver only on the desktop backdrop instead. I haven't figured out yet just how often I'd want to change it, but often enough that I wouldn't get bored with the background. Is this possible? If it is, where would I start, as far as types of scripts, etc. (I suppose there are different categories of scripts, aren't there? :? ) Thanks, JP

 PostPosted: Mon Dec 08, 2008 5:17 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
You can do it with a cronjob I think.

What you need to do is just write a script that randomly selects an image and then uses Esetroot or something like that do change your image via a cronjob.

I don't really remember it all but you can get a random number from $RANDOM and the use of modulus (i believe anyway :P).
num_files=$(ls $img_path | wc -l)
my_random=$RANDOM % $num_files

for i in $(ls $img_path); do
   if [ $x -eq $my_random ]; then
       Esetroot $i
       exit 0
   let x=x+1   

Something like that might work :) you coiuld also do this by setting a sleep X-seconds and let it run constantly... but i'd do it with a cronjob instead.

(As usual it's untested :P)

 PostPosted: Mon Dec 08, 2008 5:45 am   
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 265
Location: London - UK
This isn't what your after but it's similar and I like it :)

This is the script I use to grab pics from the NASA astronomy picture of the day website

I cron it to run each morning before I get in. Run it once and set your desktop background to be the downloaded picture. Some desktops will auto detect that the picture has changed but others will not notice unless you re-login or refresh the desktop. Windows is like that lol.

This is actually a slightly tweaked version of my script as it used some of my production logging code, which I removed as it's unnecessarily bulky for such a little script. Change some of the >/dev/null to >> $LOGFILE if you need some extra debugging.
Looking at it if I wrote it now it'd likely be quite different lol.

On the rare occasions they don't have a jpg it doesn't download, as it'll likely be a video.

# Changes my desktop pic each day
# [email protected]
# Copyright (C) 2004-2008  David Stringer
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <>.

# location of pic and log
cd /home/david/scripts/desktop

echo "Starting" >> $LOGFILE
echo "$(date)" >> $LOGFILE

picname=`wget -q -O - | grep '<IMG SRC="' | head -1 | awk -F\" '{ print $2 }' 2>>/dev/null`

echo "  picname=$picname" >> $LOGFILE
if echo $picname | egrep '.jpg' >/dev/null
  echo "Grabbing $picname" >> $LOGFILE
  wget -q -O downloaded.jpg$picname 2>>/dev/null
  mv -f downloaded.jpg desktop.jpg 2>>/dev/null

echo "Complete" " " >> $LOGFILE

 PostPosted: Mon Dec 08, 2008 5:44 pm   

Joined: Thu Dec 01, 2005 4:51 pm
Posts: 4
Location: Montana
Thanks guys, that gives me the answer to "Is it possible?" now I can work on learning the scripting to make it possible ;) Thanks for the examples, that'll give me a good head start ;)
Thanks, JP

BTW DarthWavy, is the same destination I'm heading for :D

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group