How do I automatically create and set wallpapers based on random quotes?

2

4

I like quotes very much and would like to display it on my desktop as wallpaper.

Printed quote on the middle of the plain image as desktop wallpaper.

Is there any software to do this job? I know there are plenty of software to display random images as wallpaper, but this one should generate images with text and display it as wallpaper.

ukanth

Posted 2010-01-19T10:26:29.017

Reputation: 9 930

Answers

4

You could write a bash script to do this for you. Based on the xplanet tutorial (for setting the wallpaper, it's some gconf-magic ;) ) and this thread for writing the text using imagemagick.

Something like this:

#!/bin/bash

convert -font "./verdana.ttf" -fill "#101411" -pointsize 33 -gravity "West" -draw "text 1,0 'foobar'" bg.png text.png
gconftool -t str -s /desktop/gnome/background/picture_filename text.png

Here we go, a full featured 'create a wallpaper to with a random quote on it', which could even be modified to 'to pick a random wallpaper to print a random quote on it'. ;)

Usage: Just look at the conf-section. Have fun!

#!/bin/bash

# This is a script which prints random quotes (gathered from files) on to
# a defined wallpaper.
# Some ideas are coming from the xplanet-script located at: http://rbrusu.com/xplanet-desktop-wallpape.html

# Written by Robert 'Bobby' Zenz (Robert.Zenz@gmx.at)
# Written for UK at Superuser.com


# Config-Section
# --------------
quote=~/quotes.txt              # Set this to a folder, for picking random files, or set
                                # set it to a file, to pick random lines
wallpaper=~/wallpapers/         # Set it to a fixed wallpaper, or to a folder to pick
                                # a random one inside that
tempPic=tempWall.png            # The name of the temporary file

textSize=33                     # The size of the text
textColor="#555555"             # The color of the text (watch the quotation marks!)

sleep=3m                        # Set how long the script will pause before
                                # picking a new wallpaper/quote
#---------------


# Global variable, please ignore this...
pickedFile=GlobalyDefined
pickedQuote=GlobalyDefined
pickedWallpaper=GlobalyDefined

function getRandomLine {
    pickedQuote=$(shuf -n 1 $1)
}

function getRandomFile {
    cd $1

    set -- *
    length=$#
    random_num=$(( $RANDOM % ($length + 1) ))

    pickedFile=${!random_num}

    while [ ! -e $pickedFile ]; do
        pickedFile=${!random_num}
    done

    pickedFile=$(pwd)/$pickedFile

    cd -
}

function main {
    if [ -d $quote ]; then
        getRandomFile $quote
        pickedQuote=$(cat $pickedFile)
    fi
    if [ -f $quote ]; then
        getRandomLine $quote
    fi

    if [ -d $wallpaper ]; then
        getRandomFile $wallpaper
        pickedWallpaper=$pickedFile
    fi
    if [ -f $wallpaper ]; then
        pickedWallpaper=$wallpaper
    fi

    convert -fill "$textColor" -pointsize $textSize -gravity "Center" -draw "text 1,0 '$pickedQuote'" $pickedWallpaper $tempPic
    gconftool -t str -s /desktop/gnome/background/picture_filename $tempPic

    sleep $sleep
    exec $0
}

main

That script now has a home at GitHub.

Bobby

Posted 2010-01-19T10:26:29.017

Reputation: 8 534

this is cool ;) i'll check it . now windows turn :) – ukanth – 2010-01-19T11:24:35.043

excellent, i am writing one for windows ;) some improvement

  • instead of reading a each file from folder,just a single file with each quote in a line will be good
  • Some timer functionality to change it automatically.
  • < – ukanth – 2010-01-20T06:26:45.310

@UK: Good ideas, I changed that. ;) – Bobby – 2010-01-20T23:12:45.700