Page 1 of 7 123 ... LastLast
Results 1 to 10 of 63

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

  1. #1
    Join Date
    Jul 2006
    Beans
    71

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

    Ok, on these forums I found very silly ways to change your desktop picture randomly at intervals. Some involved installing programs, daemons, or using python(!) to achieve this simple task. Here is the solution, using plain old methods.

    First, a shell script is used. This will do most of the work - basically the windows equivalent is a batch file, except this is advanced. This is the code, pretty intuitive:

    Code:
    #!/bin/bash
    
    # Set your folder with the pics
    picsfolder="/media/documents/Desktops/"
    
    # Go to your folder with the pics
    cd $picsfolder
    
    # Create an array of the files
    files=(./*/*.jpg)
    
    # Get the size of the array
    N=${#files[@]}
    
    # Select a random number between this range
    ((N=RANDOM%N))
    
    # Get the name of this file
    # a bit overly complicated. basically it takes the Nth string from files ${files[$N]}, and then removes the first two letters which is the "./" at the beginning 
    randomfile=`echo ${files[$N]} | cut --characters="1 2" --complement`
    
    # start of gconftool command and set the desktop
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomfile"
    Note that the last command is what does the work - it calls a program to set this "registry key" thing to point to your new file. Now to actually make this code do stuff, we have to save it to a file. In a terminal do this:

    Code:
    execute: gksu gedit
    paste the above code
    save to: /bin/changewallpaper.sh
    exit the gedit
    execute: gksu chmod +x /bin/changewallpaper.sh
    now we have a script to change the wallpaper. we have also made the file executable (+x). you can run it in your terminal by typing changewallpaper.sh
    Now to make it run every so often, you use cron - a schecheduling program that most linux distributions has. In a terminal do this:

    Code:
    execute: crontab -e
    add an extra line: */15 * * * * changewallpaper.sh
    add an extra line: @reboot changewallpaper.sh
    press: control+x
    press: y
    press: enter
    what that means is that every 15 minutes and every time the computer starts, it will run changewallpaper.sh
    modify that 15 if you want.
    check http://mkaz.com/ref/unix_cron.html for more cron info

    Notes
    Here are some other suggestions, and some seem better
    http://www.ubuntuforums.org/showpost...6&postcount=14
    http://www.ubuntuforums.org/showpost...4&postcount=13

    Troubleshooting
    Copied from http://www.ubuntuforums.org/showpost...8&postcount=16
    If your wallpapers do not change, just add them to the gnome wallpaper manager. After it seems like the wallpapers change

    Quoted from pt123:
    I get the error:
    scripts/changeWallpaper.sh: 10: arith: syntax error: "RANDOM%921+1"
    pt123's solution:
    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:
    Code:
    rm /bin/sh
    then
    ln -s /bin/bash /bin/sh
    Last edited by davidY; March 4th, 2007 at 06:43 AM.

  2. #2

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

    Nicely done. I'll give this one a try with feh too, and see if it does the same thing without gconftool.
    Ubuntu user #7247 :: Linux user #409907
    inconsolation.wordpress.com

  3. #3
    Join Date
    Apr 2006
    Beans
    140

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

    Thank your for this nice how-to

  4. #4
    Join Date
    Jul 2006
    Beans
    71

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

    Yeah, the problems with earlier shell scripts is that they would often impose restrictionso n file names - like no spaces, or no subdirectories.

    I think gconftool is probably the easiest - it is installed auto with ubuntu right? so everybody can use it. Although feh seems pretty cool

  5. #5
    Join Date
    Apr 2005
    Beans
    75
    Distro
    Dapper Drake Testing/

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

    I use desktop drapes. Works well. Just a few bugs from times to time. Look into it. It's got a GUI.

  6. #6
    Join Date
    Jul 2006
    Beans
    71

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

    That is true GUI > CLI when it is for people who want it. But i didn't know about this, so I had to write 5 lines of shell code *sad*.....

    On the plus side if I learnt tcl/tk, i could probably whip up a (dodgy) GUI for this to install a crontab, and to install the script...

  7. #7
    Join Date
    Nov 2005
    Beans
    127
    Distro
    Ubuntu 5.10

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

    Thank you very much! This is really nice!

    One question though: how do I make the array read files from 2 or more seperate directories? Would a "files=(./dir1/*.jpg ./dir2/*.jpg)" work?

  8. #8
    Join Date
    Jun 2005
    Location
    China
    Beans
    91
    Distro
    Ubuntu Karmic Koala (testing)

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

    anyone know why i would be getting "10: Syntax error: "(" unexpected"?

    it is the line 'files=(./*/*.jpg)' that is being complained about, but i cant find any difference between that and the code given?

  9. #9
    Join Date
    Jul 2006
    Location
    Córdoba, Argentina
    Beans
    1,341
    Distro
    Ubuntu 11.04 Natty Narwhal

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

    davidY,
    in
    Code:
    execute: gksu gedit
    paste the above code
    save to: /bin/changewallpaper.sh
    exit the gedit
    execute: gksu chmod +x /bin/change.sh
    shouldn't it be

    Code:
    execute: gksu gedit
    paste the above code
    save to: /bin/changewallpaper.sh
    exit the gedit
    execute: gksu chmod +x /bin/changewallpaper.sh
    ?
    Mariano
    Ubuntu Linux User Group Argentina
    Let's all get up and dance to a song/ That was a hit before your mother was born/ Though she was born a long long time ago

  10. #10
    Rui Pais's Avatar
    Rui Pais is offline Chocolate-Covered Ubuntu Beans
    Join Date
    Oct 2004
    Beans
    2,324

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

    or more easily:

    Code:
    gksudo gedit /bin/changewallpaper.sh
    save and exit
    sudo chmod +x /bin/changewallpaper.sh
    ___________________________________
    ESTRAGON: We've lost our rights?

Page 1 of 7 123 ... 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
  •