SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2008-12-15 03:46:49

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Rotating desktop wallpapers

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. The script can be called in place of Nitrogen in Openbox's autostart file, or better still, it can be called via a crontab entry; when called via cron it turns your desktop into a nifty image slideshow.

The script works by analysing the user supplied directory looking for image files (jpgs and pngs), it counts the number of images in the directory and then displays the first image before saving a count for the next time it runs. The next time the script is called, it reads in the count and displays the next image, provided the same directory was given.

For example, imagine I have a directory containing photographs of my favourite Muppet characters. The directory is located at ~/images/muppets, so I call the script with the following command:

rotate-wallpaper --path ~/images/muppets

When I want to change my wallpaper to the next image in the directory, I simply run the above command again.

As mentioned at the beginning, 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.

As I mentioned, I have packaged the script and it is available via CrunchBang's repository. It can be installed with the following terminal command:

sudo apt-get update && sudo apt-get install rotate-wallpaper

Notes:

  • I have only done limited testing on my own system. It would be good if others would test the script and provide feedback/bug reports.

  • The script interacts with Nitrogen and all images are scaled.

  • I did not spend too much time writing or perfecting the script and I am sure it can be optimised. In fact, knowing there are a gazillion different ways to skin a penguin in Linux, I suspect the script could probably be reduced to 1 line. big_smile Anyhow, the script can be inspected here. Please feel free to use the pastebin to modify and improve.

I hope someone finds this useful and/or fun. smile

Last edited by corenominal (2009-04-29 07:08:55)

Offline

Help fund CrunchBang, donate to the project!

#2 2008-12-15 17:46:35

trendyteddy
Member
From: Bangkok - Thailand
Registered: 2008-12-04
Posts: 19
Website

Re: Rotating desktop wallpapers

Thank you so much, corenominal.

I've just downloaded this script via APT.
I wrote a simple script and add to my .conkyrc file, like this.

${execi 60 ~/.conkyscripts/rotatew.sh}

Rotate-wallpaper updates my desktop wallpaper every 60seconds (interval=60).

Life's more eye-candy. smile

Last edited by trendyteddy (2008-12-15 17:50:24)


Pls bear to my English, I'm just a #! Tux rider from Thailand.
(less than 5% can communicate in English tongue)

Offline

#3 2008-12-16 09:48:02

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Re: Rotating desktop wallpapers

No problem, I am glad you like it. smile

Good tip with the Conky command, it had not occurred to me to use Conky to call the command. Nice one!

Offline

#4 2009-01-19 21:44:05

Mehall
#! Die Hard
From: Scotland, Cold
Registered: 2009-01-17
Posts: 850
Website

Re: Rotating desktop wallpapers

You said it''s in the #! repository... what's needed to do to make it look in the places you want for pics/change time change for the script?

Or does it ask for this info when you install the app?

Just a nice quick how-to would be nice.

Also: once all bugs are found/ironed out, will this be put into main crunchbang? (Or at least linked to somewhere talking about wallpapers? eg a button that says "Install desktop-changer here" on a settings changer for the wallpaper?)

And sorry if I seem like I'm talking crap, I haven't changed my wallpaper yet =P


Ex-KDE user.
Collects old PC's (Coz he can't afford new ones =P)
Crunchbang @ Distrowatch
My Blog (updated infrequently, and on the #! Planet too.)

Offline

#5 2009-01-20 02:01:18

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Re: Rotating desktop wallpapers

Mehall wrote:

Just a nice quick how-to would be nice.

Hello Mehall smile

Sorry to ask, but did you actually read the post, or just skim it? If you did read it, please let me know which parts are unclear and I will try to elaborate. smile

Offline

#6 2009-01-20 02:10:23

Mehall
#! Die Hard
From: Scotland, Cold
Registered: 2009-01-17
Posts: 850
Website

Re: Rotating desktop wallpapers

corenominal wrote:
Mehall wrote:

Just a nice quick how-to would be nice.

Hello Mehall smile

Sorry to ask, but did you actually read the post, or just skim it? If you did read it, please let me know which parts are unclear and I will try to elaborate. smile

ignore me, it's been a long day =P


(though it hadn't been when I posted that =/   )


Ex-KDE user.
Collects old PC's (Coz he can't afford new ones =P)
Crunchbang @ Distrowatch
My Blog (updated infrequently, and on the #! Planet too.)

Offline

#7 2009-01-20 02:29:33

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Re: Rotating desktop wallpapers

Mehall wrote:

ignore me, it's been a long day =P


(though it hadn't been when I posted that =/   )

No problem, I have those all the time. big_smile

Offline

#8 2009-02-03 09:11:56

tawan
#! Junkie
Registered: 2009-01-30
Posts: 385
Website

Re: Rotating desktop wallpapers

I couldn't save in crontab so did the following....

1) open pcmanfm as root (many ways to do including gksudo pcmanfm)

2) get to etc and make a new text file called cron.allow

3) open that as root and type

root
your-user-name

save it

4) terminal

export EDITOR=gedit
crontab -e

5) in gedit type

* * * * * DISPLAY=:0.0 rotate-wallpaper -p /usr/share/backgrounds

will rotate the contents of /usr/share/backgrounds every minute

Last edited by tawan (2009-02-03 09:25:05)


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

Offline

#9 2009-04-29 06:25:26

muppetjones
Member
From: Chapel Hill, NC
Registered: 2009-04-08
Posts: 14
Website

Re: Rotating desktop wallpapers

I really like this script! Thank you so much for providing it.

I wanted the ability to have a random wallpaper with multiple possible directories and other possibilities than just stretched, so I rewrote your script to include these. It's not too terribly efficient; so long as the directories are small, it shouldn't be a problem.

I put mine in my /usr/bin/ folder, so I can call it like this:

$ rotate-wallpaper-2 <format> <directory> <format2> <directory2> ... <formatn> <directoryn>

where format is either stretched or centered
i.e.

$ rotate-wallpaper-2 stretched ~/pictures/desktops/ centered ~/pictures/xkcd/

EDIT: Make sure you have the ending '/' on the directory. It's late and my brain is fried, so I'll have to rewrite to handle this later.

It's not quite as refined as the original (I don't check for the command line flags -- it basically takes a format then the applicable directory and so on), but it does check that each directory is a directory, and it makes sure each input is either .jpg or .png.

I have only minimally tested this on my own system, so let me know if there are any problems.

Also, this is my first "submission" on any sort of project other than my own personal projects, so I'm not really sure how the licensing works -- being in the science field, I hesitate to put Philip's name as an owner on anything he has not approved, but I'm not sure if it works that way here. Parts of it are taken directly from his in order to save time, so please let me know how to do this smile.

Let me know what you think!

#!/bin/bash

# Author: 
#     Stephen J Bush <muppetjones@gmail.com> 
# Copyright:
#   © 2009 Stephen J Bush <muppetjones@gmail.com>
#
# This script is a rewrite of rotate-wallpaper from 
# Philip Newborough <corenominal@corenominal.org>. 
# Much of this script was copied directly from his.
#
# License:
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Lesser General Public
#   License as published by the Free Software Foundation; either
#   version 2.1 of the License, or (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   Lesser General Public License for more details.
#
#   You should have received a copy of the GNU Lesser General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#   On Debian systems, the complete text of the GNU Lesser General Public
#   License V2.1 can be found in the file `/usr/share/common-licenses/LGPL-2.1'.
#-------------------------------------------------------------------------------  

    COUNT=0
    IMAGES=[]
    IMG_TYPE=[]
    TYPE_COUNT=0
    for i in "$@"; do
        if [ -d "$i" ]; then
            for j in "$i"*; do
                FILE_TYPE=$(file -i "$j")
                if [ "$FILE_TYPE" = "$j: image/png" ] || \
                [ "$FILE_TYPE" = "$j: image/jpeg" ];then
                    IMAGES["$COUNT"]=$j
                    IMG_TYPE["$COUNT"]=$TYPE_COUNT
                    COUNT=$((COUNT + 1))
                fi

            done
        fi
        if [ ! -d "$i" ]; then
            TYPE_COUNT=$((TYPE_COUNT + 1))
            TYPE["$TYPE_COUNT"]=$i
        fi
        
    done

     # Sanity check. Does config directory exist?
    if [ ! -d ~/.config/rotate-wallpaper-2 ]; then
        mkdir ~/.config/rotate-wallpaper-2
    fi
# Sanity check. Does config file exist?
    if [ ! -f ~/.config/rotate-wallpaper-2/count ]; then
        touch ~/.config/rotate-wallpaper-2/count
        echo "0" > ~/.config/rotate-wallpaper-2/count
    fi

# Get  wallpaper number
    PREVIOUS_WALLPAPER="$(cat ~/.config/rotate-wallpaper-2/count)"
    PICK_IMG=$RANDOM
    let "PICK_IMG %= $COUNT"

# ensure it's a new one
    while [ "$PREVIOUS_WALLPAPER" == "$PICK_IMG" ]; do
        PICK_IMG=$RANDOM
        let "PICK_IMG %= $COUNT"
    done

#echo $PICK_IMG $PREVIOUS_WALLPAPER

# implement
    if [ ${TYPE[${IMG_TYPE[$PICK_IMG]}]} == "centered" ]; then
        #echo "centered!" ${IMAGES["$PICK_IMG"]}
        nitrogen --set-centered "${IMAGES[$PICK_IMG]}"
    fi
    if [ ${TYPE[${IMG_TYPE[$PICK_IMG]}]} == "stretched" ]; then
        #echo "stretched!"
        nitrogen --set-stretched "${IMAGES[$PICK_IMG]}"
    fi

    echo "$PICK_IMG" > ~/.config/rotate-wallpaper-2/count
exit

Last edited by muppetjones (2009-04-29 06:33:17)


----------
"History is a nightmare from which I am trying to awake."
~ Stephen Dedalus
Ulysses by James Joyce

Offline

#10 2009-04-29 07:02:22

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Re: Rotating desktop wallpapers

Hello muppetjones smile

Nice work, I will check it out when I get a chance. Regarding the license, I am quite relaxed about it, I think I only included a license because I packaged the script. Also, I have to be honest, I had forgotten all about this, so I went to check the link in my original post and noticed the pastebin was empty. hmm I guess I posted it before I fixed the pastebin; strangley, it used to delete permanent pastes. I will repaste and edit the original post.

Anyhow, thank you for sharing and welcome to the forums! smile

P.S. Muppets Rule!

EDIT: original post updated with new pastebin location.

Last edited by corenominal (2009-04-29 07:10:08)

Offline

#11 2009-04-30 17:32:34

muppetjones
Member
From: Chapel Hill, NC
Registered: 2009-04-08
Posts: 14
Website

Re: Rotating desktop wallpapers

Regarding the license, I am quite relaxed about it,

Cool. Well, let me know if you change your mind. There needs to be a works cited to a license smile.

P.S. Muppets Rule!

nice 8^).


----------
"History is a nightmare from which I am trying to awake."
~ Stephen Dedalus
Ulysses by James Joyce

Offline

#12 2009-05-04 16:54:41

Hannus
Member
From: Estonia
Registered: 2009-04-21
Posts: 21

Re: Rotating desktop wallpapers

Could anybody give me a helping hand. The problem is, I installed "rotate wallpaper", I typed "crontab -e", added the line:

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

(1 minute for testing purposes and /wallpapers, because this is the directory where I'm holding my wallpapers).
Nothing happens.. what am I doing wrong? Is there a way to check whether my cron is working at all?
I'm using #! Lite.

EDIT: Oh and just incase:

env | grep DISPLAY
DISPLAY=:0.0

So that the display line should be right..

EDIT2: Oh and rotate-wallpaper -p ~/images/wallpapers works just fine..

Last edited by Hannus (2009-05-04 16:59:36)

Offline

#13 2009-05-08 03:11:08

myh3adhur7s
Member
From: Milwaukee, WI
Registered: 2009-04-20
Posts: 12

Re: Rotating desktop wallpapers

OK I know i am going to sound like a idiot and n00b. The later i will not deny being true right now.(at least in the area of programing and linux) This is my first instal of crunchbang but i want more. It has become my crack.  I love this rotating wallpaper but i can't get it to work at all. I need the most idiot proof way of explaining how to go about getting this to work for me.

I thank you alot.


Give me a piece of metal and i shall make anything you want.

Offline

#14 2009-05-08 03:34:10

kBang
#! Die Hard
From: Calera, AL, USA
Registered: 2009-01-06
Posts: 774

Re: Rotating desktop wallpapers

myh3adhur7s wrote:

OK I know i am going to sound like a idiot and n00b. The later i will not deny being true right now.(at least in the area of programing and linux) This is my first instal of crunchbang but i want more. It has become my crack.  I love this rotating wallpaper but i can't get it to work at all. I need the most idiot proof way of explaining how to go about getting this to work for me.

I thank you alot.

If you also use conky, I recommend you do what was in the second post:

trendyteddy wrote:

Thank you so much, corenominal.

I've just downloaded this script via APT.
I wrote a simple script and add to my .conkyrc file, like this.

${execi 60 ~/.conkyscripts/rotatew.sh}

Rotate-wallpaper updates my desktop wallpaper every 60seconds (interval=60).

Life's more eye-candy. smile

I had trouble setting up a cron event so I just went with this method.


I view KDE like I view snow. It looks fun and marvelous, it's fun to play in, but after a while I just want someone to take it all away.

Offline

#15 2009-05-13 20:01:21

scanes2
Member
Registered: 2009-05-12
Posts: 12

Re: Rotating desktop wallpapers

Thanks! its a great script!

Last edited by scanes2 (2009-05-16 21:15:31)

Offline

#16 2009-07-30 22:02:10

MDepisode
New Member
Registered: 2009-03-28
Posts: 2

Re: Rotating desktop wallpapers

muppetjones wrote:

I really like this script! Thank you so much for providing it.

I wanted the ability to have a random wallpaper with multiple possible directories and other possibilities than just stretched, so I rewrote your script to include these. It's not too terribly efficient; so long as the directories are small, it shouldn't be a problem.

...

muppetjones:

Very useful (modified) script.  Haven't used it much yet, but it seems to be working well.  One thing I noticed, however, is that the stretched option doesn't work; alas, I couldn't find a stretched option for nitrogen.  I simply edited your script by replacing every mention of the word stretched with scaled and that seems to have done the job.

Thanks so much for the script! (and of course to you as well corenominal!)

Last edited by MDepisode (2009-07-30 22:04:32)

Offline

#17 2009-07-30 22:39:35

rigosantana3
Banned
Registered: 2009-02-10
Posts: 312

Re: Rotating desktop wallpapers

Can u find some way to make this work on *barf* Fedora?
[sorry, i gotta go puke every time i say that name, brb]

Offline

#18 2009-07-30 23:03:33

anonymous
The Mystery Member
From: Arch Linux Forums
Registered: 2008-11-29
Posts: 9,418

Re: Rotating desktop wallpapers

First install Nitrogen, then just copy the script:

http://crunchbanglinux.org/pastebin/235

into your ~/bin folder and it should work.

Offline

#19 2009-07-30 23:42:50

rigosantana3
Banned
Registered: 2009-02-10
Posts: 312

Re: Rotating desktop wallpapers

Wow anonymous- once again, you are a genius

Offline

#20 2009-08-04 08:32:53

JohnQUnknown
New Member
Registered: 2009-08-04
Posts: 1

Re: Rotating desktop wallpapers

Hello there, first off i want to say that the script is really awesome, i really like it, but there was something that i wanted to add, and that is subdirectory support, so i decided to do something about it, and that's what i just did, even though it's not perfect (yet), i have splitted my idea in 3 different scripts, based (or i should say copied from) the scripts by muppetjones and corenominal, basically there's 3 scripts, the main one (the changer), the subdirectory reader, and the launcher, and i thought i could share it to see if anyone here could improve it to make it just one file with functions or something, i tried but i failed terribly sad, so here they are:

change-background.sh (main):
This is basically the same one by muppetjones, so i won't repost it smile

subd_chooser (The subdirectory chooser):

#!/bin/bash
IMAGES=[]
COUNT=0
for i in "$@"; do
    if [ -d "$i" ]; then
        #echo "i=$i"
        cd $i
        DIRECTORIES=($(ls -d */))
        #echo "DIRECTORIES = $DIRECTORIES"
        element_count=${#DIRECTORIES[@]}
    echo -n "scaled $i "
        for j in "$element_count"; do
            for index in $(seq 0 $((${#DIRECTORIES[@]} - 1)))
            do
                echo -n "scaled "
                echo -n "$i${DIRECTORIES[$index]} "
                COUNT=$((COUNT + 1))
            done
        done
    fi
done

wall_change (The one that actually applies the background):

#!/bin/bash
#getting the directories
subd_chooser $@ > ~/.config/rotate-wallpaper-2/directories
#changing the backgound
change-background.sh $(cat ~/.config/rotate-wallpaper-2/directories)

And the way I apply it is with the following command:

~$ wall_change /path/to/directory

There's something else, when you feed it a directory with no subdirectories i shows an error, but still continues...hope I can find a solution for it, or if someone have any ideas to improve this, go ahead and apply it...and really, thank you muppetjones and corenominal for sharing this script...

Last edited by JohnQUnknown (2009-08-04 08:34:59)

Offline

#21 2009-08-05 07:28:57

anu
New Member
Registered: 2009-08-04
Posts: 1

Re: Rotating desktop wallpapers

Hello.

Nice script, i run it from crontab. Anyway it does not handel symlinks ! And that truly lame...
I created small directory named wallpapers. I have to manny fotos in my piktures direktory that is on other hard disk.
So i symlinked what i need in to wallpapers as i always do , with loot of kind same situations.

Sad but it not reads those files. So whats teh funny thing here ?

opera3s.jpg

Btw, tryed with real files, works.. So how to enable symlinks :D ?

And i see there is some ones add to script like stretching, multiple directories, didnt understand how to implement it - that one doesent work for me.

Last edited by anu (2009-08-05 07:30:10)

Offline

#22 2009-08-13 23:48:37

MissPride
Member
Registered: 2009-08-11
Posts: 15

Re: Rotating desktop wallpapers

Two questions:

Is there a specific folder I should relocate the script to upon downloading?

Second, if I want the wallpaper change to take place every minute from startup automatically, would I do add the script to my crontab file or .conkyrc file.

I am new to non-GUI-based reconfigurations.  Any guidance would be greatly appreciated, please and thank you! smile

Offline

#23 2009-08-15 12:19:20

corenominal
WRONG
From: Lincoln, UK
Registered: 2008-11-20
Posts: 5,057
Website

Re: Rotating desktop wallpapers

MissPride wrote:

Is there a specific folder I should relocate the script to upon downloading?

If you are installing the original package version, there is no need to worry about relocating the script as the package should put it in your system's $PATH. If you are downloading a modified version, you might want to put it in your personal bin directory, ~/bin. By default, your personal bin directory is also included in your system's $PATH variable.

Second, if I want the wallpaper change to take place every minute from startup automatically, would I do add the script to my crontab file or .conkyrc file.

Either should work; however, if you are not familiar with setting up crontab entries, trendyteddy's Conky solution might be easier.

Offline

#24 2009-08-15 17:14:25

MissPride
Member
Registered: 2009-08-11
Posts: 15

Re: Rotating desktop wallpapers

Thanks for the response, corenominal! smile

I decided to dive into unknown territory and gave it a shot with crontab, anyway.  I'm now happily watching my wallpaper change in the background every 2.5 minutes via the cron job I set up. big_smile  (The .5 was just to see if crontab would accept decimals - it does.)

On a side note, I found a nice explanation on creating crontabs at http://www.adminschoice.com/docs/crontab.htm that helped me feel more at ease with the task when I was staring at the cryptic terminal screen as it screamed at me:

# M   H   MDAY  MON  DOW   COMMAND!!  COMMAND!! 

(Well, I found it after I back came out of hiding anyway.) hmm'

EDIT:
Also, for other total newbies out there:
"Just save the crontab to the path supplied. When its saved it should be installed" and then you'll receive the notification:

crontab: installing new crontab

(From http://forum.dreamhosters.com/troublesh … cript.htm)

The thought of a task being saved in a temp folder confused me until I read that.  Hope this helps someone out there. smile

Last edited by MissPride (2009-08-15 17:29:56)

Offline

Help fund CrunchBang, donate to the project!

#25 2009-09-14 22:00:20

toor58
#! Member
From: USA
Registered: 2009-01-10
Posts: 65

Re: Rotating desktop wallpapers

Thanx Corenominal for this script. Just implemented as per your guide at the start of this thread, and all is working great. Quality work, just like #! itself. Thanks again big_smile

Michael


smile Free your Software -- Free your Life smile

    ASUS eee pc 1005HA -- awesome#!

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo