Page 7 of 7 FirstFirst ... 567
Results 61 to 63 of 63

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

  1. #61
    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

    does the script run when you run it from a terminal. i.e.
    Code:
    sh changewallpaper.sh

  2. #62
    Join Date
    Oct 2010
    Beans
    1

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

    Hello, how change pictures automatic each 4 0 5 minutes? It can?
    Sefirot

    Quote Originally Posted by pt123 View Post
    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

  3. #63
    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

    you can use cron to run the above script at intervals

    I don't want to go into this . This thread deals Cron comprehensively
    http://ubuntuforums.org/showthread.php?t=102626

Page 7 of 7 FirstFirst ... 567

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
  •