Re: Rotating desktop wallpapers

If you use nitrogen then this script does the job in much less code

#! /bin/bash
WALLPAPERS="/your/path/to/backgrounds"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
nitrogen --set-scaled --save $WALLPAPERS/${ALIST[$number]}

Ok, maybe it's not so well commented or something but it does the job nicely.

I blog too much....       geek stuff LinuxMintDebian | linux noob stuff LinuxMintNoob | spiritual stuff Daily Cup of Tao

Re: Rotating desktop wallpapers

tawan wrote:

If you use nitrogen then this script does the job in much less code

#! /bin/bash
WALLPAPERS="/your/path/to/backgrounds"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
nitrogen --set-scaled --save $WALLPAPERS/${ALIST[$number]}

Ok, maybe it's not so well commented or something but it does the job nicely.

Nice script. smile

With regards to the original, it was just a quick hack. Also, it should be noted that as well as the comments, the original contains a few sanity checks, to stop nasty things happening. wink

Re: Rotating desktop wallpapers

This is awesome. I love it.

Question though...I noticed that Nitrogen has command-line options for "Best" but it doesn't seem to work when called from the script. Also, when I start up the GUI for nitrogen there is an option for "Zoomed" which seems to best suit the particular wallpapers I like. This doesn't appear to be supported in the cl version though. Is there a way around this?

Re: Rotating desktop wallpapers

tawan wrote:

If you use nitrogen then this script does the job in much less code

#! /bin/bash
WALLPAPERS="/your/path/to/backgrounds"
ALIST=( `ls -w1 $WALLPAPERS` )
RANGE=${#ALIST[@]}
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
nitrogen --set-scaled --save $WALLPAPERS/${ALIST[$number]}

Ok, maybe it's not so well commented or something but it does the job nicely.

I try it, it's good.

Just a question : what is the frequency of rotations of the wallpapers ? (I don't understand what in the scrit can command that, sorry ? big_smile)

wink

Re: Rotating desktop wallpapers

iomtalach wrote:

Question though...I noticed that Nitrogen has command-line options for "Best" but it doesn't seem to work when called from the script. Also, when I start up the GUI for nitrogen there is an option for "Zoomed" which seems to best suit the particular wallpapers I like. This doesn't appear to be supported in the cl version though. Is there a way around this?

Hmm, I am not running Nitrogen at the moment and so I cannot test this, but what arguments did you try? Do either of these work?

--set-auto

^ for best? Or:

--set-zoom

^ for zoomed.

Re: Rotating desktop wallpapers

Kookaburra wrote:

Just a question : what is the frequency of rotations of the wallpapers ? (I don't understand what in the scrit can command that, sorry ? big_smile)

This script just changes the wallpaper. You need to call it from conky or cron or something and set the frequency there.

You can also call this script as part of autostart or any other place.

I blog too much....       geek stuff LinuxMintDebian | linux noob stuff LinuxMintNoob | spiritual stuff Daily Cup of Tao

Re: Rotating desktop wallpapers

corenominal wrote:
iomtalach wrote:

Question though...I noticed that Nitrogen has command-line options for "Best" but it doesn't seem to work when called from the script. Also, when I start up the GUI for nitrogen there is an option for "Zoomed" which seems to best suit the particular wallpapers I like. This doesn't appear to be supported in the cl version though. Is there a way around this?

Hmm, I am not running Nitrogen at the moment and so I cannot test this, but what arguments did you try? Do either of these work?

--set-auto

^ for best? Or:

--set-zoom

^ for zoomed.

I get "Unexpected argument" for both those. Other options call up the GUI, which is sort of fun. smile

Looks like an oops in nitrogen.

Re: Rotating desktop wallpapers

Thanks corenominal for this script. Very nice. I registered here just so I could thank you. Though I don't run crunchbang I found your script interesting and decided to revise it to run under Ubuntu (Gnome). I thought I'd share it with the hope that someone could use it.

#!/bin/bash

 # Get the pid of nautilus
 nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
 
 # Grab the DBUS_SESSION_BUS_ADDRESS variable from nautilus's environment
 eval $(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')

 # export it so that child processes will inherit it
 export DBUS_SESSION_BUS_ADDRESS

 # Set the path to your wallpaper directory here
 WALLPAPERS=~/Pictures
        
 # Sanity check. Is wallpapers directory empty of images?
 # + Build query
 QUERY=""
 if [ "$(ls $WALLPAPERS/*.jpg 2> /dev/null)" ]; then
    QUERY="$QUERY$WALLPAPERS/*.jpg "
 fi
 if [ "$(ls $WALLPAPERS/*.JPG 2> /dev/null)" ]; then
    QUERY="$QUERY$WALLPAPERS/*.JPG "
 fi
        
 # Sanity check. Does config directory exist?
 if [ ! -d ~/.config/rotate-wallpaper ]; then
    mkdir ~/.config/rotate-wallpaper
    touch ~/.config/rotate-wallpaper/count
    echo "0" > ~/.config/rotate-wallpaper/count
 fi
 
 # Count number of wallpapers
 NO_OF_WALLPAPERS=0
 for file in $QUERY; do
   if [ ! -d "$file" ];then
      NO_OF_WALLPAPERS=$(( NO_OF_WALLPAPERS+1 ))
   fi
 done
        
 # Read in number of last wallpaper displayed, or start from 1
 PREVIOUS_WALLPAPER="$(cat ~/.config/rotate-wallpaper/count)"
 NEW_WALLPAPER=$(( PREVIOUS_WALLPAPER+1 ))
   
 # Do we need to loop back to 1?
 if [ $NEW_WALLPAPER -gt $NO_OF_WALLPAPERS ];then
    NEW_WALLPAPER=1
 fi
        
 # Set wallpaper
 CNT=1
 for file in $QUERY; do
    if [ $CNT = $NEW_WALLPAPER ]; then
      if [ ! -d "$file" ];then
         gconftool-2 -t str -s /desktop/gnome/background/picture_filename "$file"
      fi
    fi
 CNT=$(( CNT+1 ))
 done
        
 # Save count and exit
 echo "$NEW_WALLPAPER" > ~/.config/rotate-wallpaper/count #original $NEW_WALLPAPER
 
 exit

My cron job is this....

*/5 * * * * ~/.chgwall/rotate-wallpaper.sh

Again thanks for such a terrific script.

Later....

Last edited by Trespasser (2009-11-13 00:58:38)

Re: Rotating desktop wallpapers

^ I am glad you found it useful! smile

Re: Rotating desktop wallpapers

Cool, I'm using it right now wink

Re: Rotating desktop wallpapers

Well, I wanted to find a version of this script that worked for doing a centered wallpaper (a request of a friend who I got into #!, whom now loves it), but alas, none of the ones that offered that worked.  I decided to do it myself.

I think I may have improved upon this code a bit as well beyond that.  I added a zenity-based graphical interface for easy rotations outside of the usual crontab automated one, and as such, I call it zen-rotate.

/bin/zen-rotate:

#!/bin/sh

##
#  zen-rotate
#
#   version 1.0
#   A nitrogen based script for wallpaper slideshows from a target directory 
#   with a zenity based user interface. 
#
#   by Kevin Mason <kmason@bloodstar.net>
#      http://bloodstar.net/
#
#   This program is distributed under the terms of the GNU General Public License
#   For more info see http://www.gnu.org/licenses/gpl.txt
##

help(){
echo "This program uses nitrogen to make a wallpaper slideshow from a target directory, with zenity for optional GUI."
echo "Usage: zen-rotate -h -g -c -s."
echo "Options: One option is required, but only one will be allowed."
echo "Entering a second option will result in only the first being read."
echo " -h: Displays this dialog."
echo " -g: Use a graphical user interface."
echo " -c directory: Set the scaling to centered for the target directory."
echo " -s directory: Set the scaling to scaled for the target directory."
exit 1
}

if [ $# -eq 0 ] ; then
    help
fi

while getopts 'hgc:s:' OPTION
do 
    case $OPTION in
    c) WALLPAPERS="$OPTARG";SCALING=centered;;
    s) WALLPAPERS="$OPTARG";SCALING=scaled;;
    g) . $HOME/.config/zen-rotate/ui;;
    h) help;;
    ?) help;;
    esac
done

file=`/bin/ls -1 "$WALLPAPERS" | sort --random-sort | head -1`
path=`readlink --canonicalize "$WALLPAPERS/$file"` # Converts to full path
nitrogen --set-$SCALING --save $path

/home/user/.config/zen-rotate/ui

#!/bin/sh

## User Interface for zen-rotate

## Initialize first zenity interface, a list for choosing the scaling type.
SCALING=$(zenity  --list  --text "Choose your Scaling Type." --radiolist \
--column "Pick" --column "Type" \
TRUE scaled FALSE centered);

## Initialize the second zenity interface, a file selection dialog for selecting
## the wallpaper directory.
WALLPAPERS=$(zenity  --file-selection  --title="Choose your Target Directory." --directory);

Usage:

GUI

zen-rotate -g

CLI (Centered)

zen-rotate -c /path/to/directory

CLI (Scaled)

zen-rotate -s /path/to/directory
[Acer Aspire One ZG5|Intel Atom N270|1GB RAM|8GB SSD|Intel Integrated Graphics|#! 9.04]
[Custom Desktop|Intel C2D E8400|2GB RAM|80GB & 250GB HDD|NVIDIA GeForce GT220|Win7Pro|#! 9.04]
[last.fm|deviantART|Bloodstar Studios]

Re: Rotating desktop wallpapers

Just for the record: Adcomp image changer on desktop has a full screen option
Not a changing wallpaper but a screensaver for when you don't need the desktop
See this post: http://crunchbanglinux.org/forums/post/55553/#p55553 :

What's new ?

* Fullscreen mode ( like screensaver )
* add some key 'event' :  Esc -> exit  ,  Space -> pause
* transparent border ( need composite )
* ask password .. ( not very powerful .. easily crackable )
* ..

Source : http://www.ad-comp.be/public/projets/rn … desklet.py

Last edited by pablokal (2010-02-16 12:50:34)

GNu/Linux: Nu nog schoner: http://linuxnogschoner.blogspot.com/  Dutch

Re: Rotating desktop wallpapers

Hi everyone,

this is my first post on crunchbang forum. I'm also a first time crunchbang and openbox installer. As Debian enthusiast, I enjoied "Statler" and I'm quite happy with it but I got some problems in succeding to rotate desktop wallpaper with these scripts. I have some questions:

Where have I to save these scripts?
How have I to edit these scripts with my images folder path?
How have I to edit autostart.sh to invoke these scripts?

Sorry you find my questions stupid. And sorry for my bad English...

Last edited by CaSt (2010-06-21 12:44:04)

Re: Rotating desktop wallpapers

CaSt wrote:

Where have I to save these scripts?

Try saving somewhere in your $PATH like /usr/bin/.

CaSt wrote:

How have I to edit these scripts with my images folder path?

Open the script in a text editor and change the path for folder.

CaSt wrote:

How have I to edit autostart.sh to invoke these scripts?

Just put something like:

scriptname &

As long as the script is executable and you put in your $PATH, it should work.

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Rotating desktop wallpapers

and to execute something not in the $PATH, you can just use the full location, e.g. /home/yourname/imagescript.sh

just call me...
~FSM~

Re: Rotating desktop wallpapers

Thank you very much for your quick replies and support with a numb newbie, I really appreciate it.

I solved! Basically I didn't understood that the /usr/bin folder was the place where i had to paste the scripts. I picked the one on top of this page, in post 26, only turned the  --set-scaled option in the last code line into --set-centered and edited the image folder path in the first code line. I saved as "rotate-wallpaper" and allowed the excution of the script,  then pasted in /usr/bin. I edited my autostart.sh and rebooted. It just works! Now, I'm wondering:

What's the frequency of the image rotation? How can I set it ? My system is 15 minutes up since the reboot and I haven't seen any desktop change during this time. Is this related with the crontab settings you wrote about in the previous posts? I think so, but all is so difficult to understand for me...

Thanks in advance...

Last edited by CaSt (2010-06-21 21:39:09)

Re: Rotating desktop wallpapers

CaSt wrote:

What's the frequency of the image rotation? How can I set it ?

Someone else asked the same thing:

http://crunchbanglinux.org/forums/post/44679/#p44679

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Rotating desktop wallpapers

All right, I found my answer in the first post of this thread

the script works really quite well when used as a crontab entry. Following the example above, I would create a new crontab entry with the following terminal command:

crontab -e

I would then type in my command as below and save my crontab file:

*/5 * * * * DISPLAY=:0.0 rotate-wallpaper -p ~/images/muppets

My desktop wallpaper would now be set to automatically rotate every 5 minutes.

Re: Rotating desktop wallpapers

This script is worked in centered  wallpaper. A zenity based graphical interface is easy to use for rotation. Zen rotate is very useful code for rotating desktop wallpapers.

Re: Rotating desktop wallpapers

corenominal wrote:

In response to this forum post, I wrote and packaged a little script tonight which will rotate desktop wallpapers from a given directory of images. <snipped>

corenominal, I adore your rotate-wallpaper package (#!9.04). Will it be available for Statler once released?

rippin

Re: Rotating desktop wallpapers

I took Tawan's script and modified it a little to read into subdirectories and gather images.  I have ~84 images which I received in 4 zip files - I'm not going to throw them all into one big folder!  Therefore, Tawan's script didn't do the trick.  Therefore, I came up with this script:

#!/bin/bash
WALLPAPERS="/home/chiraag/Pictures/backgrounds"
find $WALLPAPERS -type f -name "*.jpg" | sed -e 's/\/home\/chiraag\/Pictures\/backgrounds\///' | sed -e 's/ /\\ /g'> $WALLPAPERS/files.txt
RANGE=`wc -l $WALLPAPERS/files.txt | sed -e 's/\/home\/chiraag\/Pictures\/backgrounds\/files.txt//'`
let "range = $RANGE"
let "number = $RANDOM"
let LASTNUM="`cat $WALLPAPERS/.last` + $number"
let "number = $LASTNUM % $RANGE"
echo $number > $WALLPAPERS/.last
cd $WALLPAPERS
FILE=`sed -n "$number p" files.txt`
echo $FILE
nitrogen --set-scaled --save $FILE

Enjoy! big_smile

Check out Musik - an easy-to-use text-to-music converter!
Join SpiderOak using this link and get an extra 1 GB free: https://spideroak.com/download/referral … 660e787ff1

Re: Rotating desktop wallpapers

chaanakya wrote:

I took Tawan's script and modified it a little to read into subdirectories and gather images.  I have ~84 images which I received in 4 zip files - I'm not going to throw them all into one big folder!  Therefore, Tawan's script didn't do the trick.  Therefore, I came up with this script:
<snip>

Thanks for this. I'll look into messing with it. That said, with the advent of Startler - I moved to it 'cause 9.04 packages are no longer available - I found this I like to use with conky:

#!/bin/bash

#rWall is licensed under GPL v2.0 (queue inflated sense of self-importance).
#A script to select random images from the specified directories and tile them to the background.
#requires either feh or gconftool.
#Feh stores background settings in $HOME/.fehbg.
#The key for gconftool is /desktop/gnome/background/picture_filename.


#set wallpaper directory.
bgfolder=$HOME/path-to-images

#set wallpaper random.
wallpaper=$(find $bgfolder -name "*.j?g" | sort -R | head --lines=1)

#use feh
#feh --bg-center "$wallpaper"
feh --bg-fill "$wallpaper" # added for my likes
#feh --bg-scale "$wallpaper"
#feh --bg-tile "$wallpaper"

#or use gconftool, which will prevent hiding of icons and desktop right-click menu in GNOME.
#gconftool-2 -t str --set /desktop/gnome/background/picture_filename "$wallpaper"

exit

And, for .conkyrc

${execi 900/home/<username>/bin/rotate-wallpaper}
rippin

Re: Rotating desktop wallpapers

I used the following line added to crontab to cycle all the wallpapers in ~/images/wallpapers/ every minute.

* * * * * DISPLAY=:0.0 nitrogen --set-scaled "$(find ~/images/wallpapers/ -type f -iname "*.jpg" -o -iname "*.png" |sort -R |tail -1)"

Here is the breakdown:
1. DISPLAY=:0.0 #Sets the display
2. nitrogen --set-scaled #Calls nitrogen with the flag to set to scaled.
3. "$( #Opens bash scripting
4. find ~/images/wallpapers/ -type f -iname "*.jpg" -o -iname "*.png" #Calls find in the wallpapers directory looking for files that end in .jpg or .png and is case insensitive. Find outputs a list.
5. sort -R #Sorts the list randomly
6. tail -1 #Takes the last item in the list.

The only problem I have with this method and using nitrogen in general is that the wallpaper redraw causes a flash over any application. It's brief and often barely noticeable, but it's enough to be distracting when I'm coding. I'll file a bug with nitrogen, but that guy seems to be pretty busy anyway.

Good luck crunchbangers! I hope this helps.

Re: Rotating desktop wallpapers

@slashtact - maybe consider using feh instead (to set the wallpaper)?

Note: ** Please read before posting **

BTW if you wish to contact me, send me an e-mail instead of a PM.

Re: Rotating desktop wallpapers

I had the same problem with feh stealing focus briefly. Upon investigation into how feh was drawing the background I found that feh was using a similar method to xloadimage, hsetroot, and nitrogen. However, after much research and many trials I found Esetroot, a utility provided by the Eterm terminal emulator. It's dependencies are already installed in #! as well:

eterm
  Depends: libast2
  Depends: libc6
  Depends: libice6
  Depends: libimlib2
  Depends: libsm6
  Depends: libx11-6
  Depends: libxext6
  Depends: libxmu6
  Conflicts: <eterm-backgrounds>
  Conflicts: <eterm-ml>
  Replaces: <eterm-backgrounds>
    eterm
  Replaces: <eterm-ml>

So, my solution was to:

sudo apt-get install eterm

and then to add the following line to crontab -e:

* * * * * DISPLAY=:0.0 Esetroot -s "$(find ~/images/wallpapers/ -type f -iname "*.jpg" -o -iname "*.png" |sort -R |tail -1)"

No flickr, lightweight, and works wonders smile

@anonymous

I liked and disliked feh. It seems nice and lightweight, but ultimately it had the same issue as nitrogen. I tried pretty hard to get something to work with the native tools in a default crunchbang install, but this is the best I could come up with tonight. I may look into the source of Esetroot to see where the differences are in drawing the background and write a patch for nitrogen, but if I do it'll be a long way off. Thanks for the recommendation though. Cheers!

Last edited by slashtact (2011-02-24 07:15:54)