Page 2 of 7 FirstFirst 1234 ... LastLast
Results 11 to 20 of 63

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

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

    Hobbes, not sure here but I guess you need to change #!/bin/sh for #!/bin/bash in the first script.

    Anyone can tell us if it's right?

    Rui Pais: nice signature. It's always nice to see that somebody else appreciates the same writers that I do.
    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

  2. #12
    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

    Quote Originally Posted by marianom View Post
    Hobbes, not sure here but I guess you need to change #!/bin/sh for #!/bin/bash in the first script.

    Anyone can tell us if it's right?

    Rui Pais: nice signature. It's always nice to see that somebody else appreciates the same writers that I do.
    it should works both ways since the code it's simple and didn't require nothing specific to one shell. I had a some problems with certain scripts on edgy due to shell change but this one don't seems to have anything problematic to edgy/dash (didn't try it)



    About Becket. Well a few moth ago i was in middle of reading Watt, when an opportunity appeared to saw 'waiting for Godot'.
    My first time i saw it . And i was amazed by the quality of text, the solutions he gets for the self raised problems, the circular absorbing essence of the wait replacing the means of the action, the motives and even the lives of the personages!...
    And then suddenly they said that 2 phrases... i was devastated with concept. More then depressing it's terrifying. Not the point of lose rights or some one take them away, but one volunteer "get rid of them".... (And worst, what was written with a burlesque, sad/comic, almost clowning intention it 's so common around us on our days, in our society... )
    ___________________________________
    ESTRAGON: We've lost our rights?

  3. #13
    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 Hobbes View Post
    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?
    I got the same error, as well as it choked on a directoy with a space in the name. Upon further investigation, I have come up with an even simpler script, which at least works on my system:
    Code:
    #!/bin/bash
    
    # Set your folder with the pics
    picsfolder="/media/documents/Desktops/"
    
    # Go to your folder with the pics
    cd "$picsfolder"
    
    # Get the name of a random file
    randomfile=`ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p`
    
    # start of gconftool command and set the desktop
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomfile"
    You can follow davidY's instructions for executing, etc.

    I also don't know if this is a quirk of my system or not, but I find I have to add all the files to the list of available backgrounds (via the Desktop Background tool) before any of the files will actually display when set.

    EDIT: you should also be able to extend this to multiple directories (provided they are sub-directories of the main directory) as follows:
    Code:
    #!/bin/bash
    
    # Set your folder with the pics
    picsfolder="/media/documents/Desktops/"
    
    # Go to your folder with the pics
    cd "$picsfolder"
    
    # Get the name of a random directory
    randomdir=`ls -d */ |sed -n $((RANDOM%$(ls -d */ |wc -l)+1))p`
    
    # Go to the selected directory
    cd "$randomdir"
    
    # Get the name of a random file
    randomfile=`ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p`
    
    # start of gconftool command and set the desktop
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomdir$randomfile"
    To deal with multiple independent directories is more complicated; I'd suggest putting them all into a file and using cat to display the line (instead of the "ls" commands) and process it similarly.

    EDIT 2: See post #22 for an improved version of the multiple directories approach.
    Last edited by tweedledee; March 4th, 2007 at 03:47 AM. Reason: clarification

  4. #14
    Join Date
    Jul 2006
    Location
    Strongbadia
    Beans
    196
    Distro
    Ubuntu 9.04 Jaunty Jackalope

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

    feel free to modify this to use random. it allows for multiple directories through a file and allows for spaces in directories and file names.
    this also makes it possible to have different wallpaper directories per user since the .directorylist file is in the users home directory

    Code:
    #!/bin/bash
    IFS=$'\n'
    ALIST=( `cat ~/.wallpaper/.directorylist` )
    COUNTER=${#ALIST[@]}
    find "${ALIST[$COUNTER-1]}" -maxdepth 1 -mindepth 1 -type f | grep ".jpg\|.png" > .wallpaperlist
    let COUNTER-=1
    until [  $COUNTER -lt 1 ]; do
    find "${ALIST[$COUNTER-1]}" -maxdepth 1 -mindepth 1 -type f | grep ".jpg\|.png" >> .wallpaperlist
    let COUNTER-=1
    done
    ALIST=( `cat .wallpaperlist` )
    RANGE=${#ALIST[@]}
    let LASTNUM="`cat .lastwallpaper` + 1"
    let "number = $LASTNUM % $RANGE"
    echo $number > .lastwallpaper
    echo "${ALIST[number]}" > .currentwallpaper
    gconftool-2 -t string -s /desktop/gnome/background/picture_filename "${ALIST[$number]}"
    Last edited by eternalsword; January 27th, 2007 at 09:39 AM.

  5. #15
    Join Date
    Jan 2006
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

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

    I tried to set this up and put the script in my home-folder. (Also written without sudo or sdgk) The pictures are also in a subfolder of home.

    Now when I execute the script, my background turnes white. Any idea why that is? (I just want to understand... )

  6. #16
    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 groova View Post
    I tried to set this up and put the script in my home-folder. (Also written without sudo or sdgk) The pictures are also in a subfolder of home.

    Now when I execute the script, my background turnes white. Any idea why that is? (I just want to understand... )
    I've tried all the variants posted here, and without exception I had to add the background pictures to my list of desktop wallpapers before the images would appear (right-click on your desktop -> change wallpaper -> add wallpaper -> select all the files you want to rotate through (you can do them all at once if they are in the same folder). This basically just seems to make Nautilus "aware" of the files.

  7. #17
    Join Date
    Mar 2007
    Beans
    23
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    I'm having the same problem as other people in this thread. No matter what I do, I get no changes in my wallpaper. I have added all my wallpapers to the wallpaper manager.

    This is my code:

    #!/bin/bash

    # Set your folder with the pics
    picsfolder="/home/matthew/wallpapers"

    # Go to your folder with the pics
    cd "$picsfolder"

    # Get the name of a random file
    randomfile=`ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p`

    # start of gconftool command and set the desktop
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$picsfolder$randomfile"


    Thanks for your help guys.
    Btw, if i don't run it under gksu, the screen goes white
    If i run it under gksu, there's no change in wallpaper.

  8. #18
    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

    Quote Originally Posted by tweedledee View Post
    randomfile=`ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p`
    what is the character in front of ls and after p is it ` the character which share the key with ~ ?

    Because when I use this and try to run the script I get this error :

    Code:
    scripts/changeWallpaper.sh: 10: arith: syntax error: "RANDOM%921+1"

    When I change it to an apostrophe i.e. '
    When I look in the gconftool for picture_filename it says
    /media/d/Collection/Wallpapers/zNew/ls *.jpg *.png |sed -n $((RANDOM%$(ls *.jpg *.png |wc -l)+1))p

    I am assuming its just quoting it.

    Can someone please tell me what the problem is?
    Last edited by pt123; March 3rd, 2007 at 10:01 PM.

  9. #19
    Join Date
    Mar 2007
    Beans
    23
    Distro
    Ubuntu 7.10 Gutsy Gibbon

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

    Never mind guys, it worked =S The Cron script works... it changes automatically, but when I run the changewallpaper script manually, it doesn't change anything 0.o
    Last edited by talcite; March 3rd, 2007 at 10:48 PM.

  10. #20
    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 it to ` now the script works in cron

    but it doesn't work when it manually i.e. sh scripts/changeWallpaper.sh

    I get the error:
    scripts/changeWallpaper.sh: 10: arith: syntax error: "RANDOM%921+1"

    What is causing this error?

Page 2 of 7 FirstFirst 1234 ... 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
  •