Register
It is currently Wed Oct 22, 2014 9:46 pm

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


Top
 Profile  
 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).
Code:
#!/bin/bash
img_path=/path/to/images
num_files=$(ls $img_path | wc -l)
my_random=$RANDOM % $num_files

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

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)


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

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
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
http://antwrp.gsfc.nasa.gov/apod/astropix.html

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.

Code:
#!/bin/bash
#
# Changes my desktop pic each day
# DarthWavyBashScripts@wavy.org
#
# desktop.sh
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# 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 <http://www.gnu.org/licenses/>.
#
#

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

echo "Starting desktop.sh" >> $LOGFILE
echo "$(date)" >> $LOGFILE

picname=`wget -q -O - http://antwrp.gsfc.nasa.gov/apod/astropix.html | grep '<IMG SRC="' | head -1 | awk -F\" '{ print $2 }' 2>>/dev/null`

echo "  picname=$picname" >> $LOGFILE
if echo $picname | egrep '.jpg' >/dev/null
then
  echo "Grabbing $picname" >> $LOGFILE
  wget -q -O downloaded.jpg http://antwrp.gsfc.nasa.gov/apod/$picname 2>>/dev/null
  mv -f downloaded.jpg desktop.jpg 2>>/dev/null
fi

echo "Complete" " " >> $LOGFILE


Top
 Profile  
 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, http://antwrp.gsfc.nasa.gov/apod/astropix.html is the same destination I'm heading for :D


Top
 Profile  
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 6 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
© 2003 - 2011 USA LINUX USERS GROUP