Page 3 of 7 FirstFirst 12345 ... LastLast
Results 21 to 30 of 63

Thread: HOWTO: Finally! How to easily change your desktop to a random file at specified times

  1. #21
    Join Date
    Jul 2005
    Beans
    740
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    I found why it wont work when called in a terminal from another forum.
    if you're running ubuntu you may find /bin/sh is symlinked to dash and not bash. sometimes you find weird errors occurring because of that.
    So the solution was:
    rm /bin/sh
    then
    ln -s /bin/bash /bin/sh

  2. #22
    Join Date
    Jul 2005
    Beans
    740
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    I changed tweedledee script so that when it looks into a subfolder and if it has no photos then to look for subfolders within the subfolder.

    I also added a seconds multiplication to the random number hoping to improve the randomisation.

    Here is the script if anyone wants it
    Code:
    #!/bin/bash
    
    # Set your folder with the pics
    picsfolder="/media/d/Collection/Wallpapers/"
    
    # Go to your folder with the pics
    cd "$picsfolder"
    
    # the seconds is used to get a better randomisation as it is  multiplied to the random number
    seconds=`eval date +%s`
    echo "$seconds"
    
    # Get the name of a random directory
    randomdir=`ls -d */ |sed -n $((RANDOM*seconds%$(ls -d */ |wc -l)+1))p`
    echo "$randomdir"
    
    # Go to the selected directory
    cd "$randomdir"
    numberOfPics=`(ls *.jpg *.png |wc -l)`
    echo $numberOfPics
    wpPath=""
    if [ $numberOfPics -lt 1 ]	# is $X less than $Y ? 
    then
    	echo "number of pics is less than 1"	
    	# Get a random sub Directory because there are no pics in folder	
    	randomSubDir=`ls -d */ |sed -n $((RANDOM*seconds%$(ls -d */ |wc -l)+1))p`
    	cd "$randomSubDir"
    	numberOfSubPics=`(ls *.jpg *.png |wc -l)`
    	echo $numberOfSubPics
    	randomSubFile=`ls *.jpg *.png |sed -n $((RANDOM*seconds%$numberOfSubPics+1))p`
    	echo $randomSubFile
    	wpPath="$picsfolder$randomdir$randomSubDir$randomSubFile"
    else
    	# there are pics in folder dont bother looking for sub directories	
    	randomfile=`ls *.jpg *.png |sed -n $((RANDOM*seconds%$numberOfPics+1))p`
    	wpPath="$picsfolder$randomdir$randomfile"
    fi
    echo $wpPath
    
    
    
    # start of gconftool command and set the desktop
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$wpPath"
    Last edited by pt123; March 4th, 2007 at 03:18 AM.

  3. #23
    Join Date
    Dec 2006
    Beans
    678

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    Quote Originally Posted by pt123 View Post
    I changed tweedledee script so that when it looks into a subfolder and if it has no photos then to look for subfolders within the subfolder.

    I also added a seconds multiplication to the random number hoping to improve the randomisation.

    Here is the script if anyone wants it
    Progress! I don't actually use the multiple directories (at least to date), but I'm glad you found it useful enough to improve upon it. I've updated my post to point to your changes.

  4. #24
    Join Date
    Jul 2005
    Beans
    740
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    A new script to change the wallpaper. What it does is grabs all the images from your wallpaper folder including sub directories. Then it creates a list and saves it to your hard disk. Then it randomly chooses a WP from the list. Whenever you run it checks to see if the number images in your list matches the number of images in your WP folder, if not it saves the updated list to disk.

    Code:
    #!/bin/bash
    
    # Set your folder with the pics
    picsfolder="/media/main/Wallpapers/"
    
    #Set the Path to the Wallpaper list will be created
    wplistpath="/home/username/wplist.txt"
    
    
    #go to the picture directory
    cd "$picsfolder"
    
    #load the list of pics to a variable
    wpDirList=`(find . -regex ".*\(jpg\|jpeg\|gif\|png\|svg\)$"  -type f)`
    #find the number of pics in the WP dir based on the extension
    numberOfPicsDir=`echo "$wpDirList" | wc -l`
    
    
    
    # Count number of pics in the Wallpaper list by counting number of lines.
    numberOfPicsList=0  #initial lise
    
    
    #check if the wallpaperlist Exists
    if [[ -e "$wplistpath" ]]
        then
           numberOfPicsList=$(wc -l < "$wplistpath")
         else
     	echo "WP list does not exist"
    fi
           
    
    # inform the user
    echo $numberOfPicsDir" --- "$numberOfPicsList
    
    # if they don't match rewrite the wallpaper list
    # this if can be removed and the list can be saved every time
    
    if [ $numberOfPicsDir -ne $numberOfPicsList ]
    then
    	#save the list to disk 	
    	echo -n "$wpDirList" > "$wplistpath"
    
    fi
    
    # Find a random line number in the wallpaper list
    r=$((RANDOM % numberOfPicsDir + 1))       # Random number from 1..n.
    
    # print what the line number is 
    picPath=`sed -n "$r{p;q;}" "$wplistpath"`   # Print the r'th line.
    wpPath="${picsfolder}${picPath#./}"     # #./ crops that substring but it doesn't matter if it left there
    echo "$wpPath" 
    
    #set the wallpaper in Gnome Config Editor
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$wpPath"

    Preferably you should break the script into two scripts one that creates the wallpaper list and this should be scheduled to run once a week and the other script that will pick an image from the wallpaper list which can be run every 5,10,15,60 mins etc.

    That said I am running this on a list of 3000+ images without problems.

    Here is a link to a good Bash FAQ/Tutorial.
    http://wooledge.org/mywiki/BashFAQ?a...direct=BashFaq
    Last edited by pt123; June 10th, 2007 at 02:33 PM. Reason: typos

  5. #25
    Join Date
    Dec 2006
    Beans
    Hidden!

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    gksu chmod +x /bin/changewallpaper.sh


    gave me:

    Code:
    (gksu:11991): Gtk-WARNING **: Unable to locate theme engine in module_path: "murrine",
    /home/dutta/.themes/snow-leopard-mac/gtk-2.0/gtkrc:41: Clearlooks configuration option "sunkenmenu" is not supported and will be ignored.
    /home/dutta/.themes/snow-leopard-mac/gtk-2.0/gtkrc:42: Clearlooks configuration option "listviewitemstyle" is not supported and will be ignored.
    /home/dutta/.themes/snow-leopard-mac/gtk-2.0/gtkrc:43: Clearlooks configuration option "progressbarstyle" is not supported and will be ignored.
    it's not working.
    I am a superhero...on a break.
    Registered Linux user #438570

  6. #26
    Join Date
    Jul 2005
    Beans
    740
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    That just gives execute permissions for the script
    the errors just on theme
    if you try
    sudo chmod +x /bin/changewallpaper.sh

    it wont show any errors

  7. #27
    Join Date
    Dec 2005
    Location
    Kingston, Ontario
    Beans
    1,919
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    Interesting script. Not something I'd use because I'm very picky about my wallpapers, but it's definitely useful! Nice work.

  8. #28
    Join Date
    Jul 2005
    Location
    2 exits past crazy
    Beans
    4,222
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    The only problem I see with the script, is that the bash RANDOM built-in is limited to 32K. That just doesn't cut it for a serious wallpaper collector like myself...

    (about 60,000 or so)

  9. #29
    Join Date
    Jul 2005
    Beans
    740
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    Thanks Loke,

    yabbadabbadont then you can create 2+ lists, depending on how you have kept your wallpapers.

    Or you can create 2 random numbers
    eg. random1x 3 + (RANDOM2 % 3)
    will handle 32,000 X 3 wallpapers.

  10. #30
    aitvo Guest

    Wink Re: HOWTO: Finally! How to easily change your desktop to a random file at specified t

    I wrote a script 4 years ago to change wallpaper randomly on a timer. This works with Gnome, WindowMaker, Fluxbox, and with a little edit any other desktop environment that can change wallpaper from a commandline.

    http://www.stangdude.com/download.pl...dy-1.23.tar.gz

    Also, it's page on gnomefiles: http://www.gnomefiles.com/app.php/Background_Buddy and it's homepage: http://www.stangdude.com/news/articles/12519005125776/
    Last edited by aitvo; January 3rd, 2008 at 02:35 PM.

Page 3 of 7 FirstFirst 12345 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •