Random wallpaper script

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
Mmmm
Posts: 22
Joined: Tue 15 Jun 2010, 19:46

Random wallpaper script

#1 Post by Mmmm »

I'm developing a script that chooses a random wallpaper on bootup for puppy linux.
I change the wallpaper by inserting the path and filename of the picture into the puppypin file. This works very nicely most of the time but I have noticed that if there is an '&' character in the filename then disaster will strike and your entire desktop will be whisked into the void and you will see it no more.

I have got around this problem by ignoring all such files but I would like to know what other characters are not supported in the puppypin file but which are allowed in filenames.

Any ideas?

Thanks...

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#2 Post by sunburnt »

Any forbidden Bash characters I`d think. "&, #, |, [, ], {, }, (, ), <, >, *, $, @, `, /, \"
You know... Most of them! . ; )

You could remove the characters from the file names before using them.
This removes most of them, "/" doesn`t need to be included of course.

Code: Select all

 NewName=`echo "FileName | sed 's#[\#\$\&\*\:\;\=\(\)\{\}\[\]\|\\<\>]##g'`
You can try others by adding them and test it to see if it works.

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#3 Post by puppyluvr »

:D Hello,
Could you call them as variables?
Something like:

for i in `cat /usr/share/backgrounds`
do
a=$i
cp $a /usr/share/backgrounds/default
done

Set up a counter to prevent repeating, and set the default randomly each time...
Just a thought...
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#4 Post by technosaurus »

here is a stub that can be use to randomize any passed parameters
just modify the sleep value and pipe it to a program that accepts pipes or use VAR=`eval echo \${$NEWVALUE}` to store the random arg

Code: Select all

#!/bin/sh
NEWVALUE=1
while ([ ! $EXIT ]) do
	OLDVALUE=$NEWVALUE
	while ([ $NEWVALUE -eq $OLDVALUE ]) do
		NEWVALUE=$(($(($RANDOM%$#))+1))
	done
	eval echo \${$NEWVALUE}
	sleep 1
done
notes
while ([ ! $EXIT ]) do <<<just a random variable it could have been anything, but I don't like to use true, because it can hog cpu

while ([ $NEWVALUE -eq $OLDVALUE ]) do << b/c we don't want the same thing twice in a row, even if it _is_ random (just remove this loop except for the random value part if this is ok)

$((integer math here))
$RANDOM generates a random number
% give the modulus (integer remainder on N%M yeilds integer values of 0 to M-1)
......we have to add 1 because $0 is the command name

eval echo \${$NEWVALUE} <<< because I don't know a better way to do this in standard shell (bash has redirection using ! but it is not portable)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Mmmm
Posts: 22
Joined: Tue 15 Jun 2010, 19:46

#5 Post by Mmmm »

Thanks for all the replies, some pretty interesting stuff there.

puppyluvr you've jogged my mind into thinking of a really simple solution which is just to copy the file to a different filename - say 'wallpaper' in the same directory and have that in the puppypin file. Then there are no more filename restrictions (apart from those on the filenames themselves)

Thank you very much... :D

User avatar
puppyluvr
Posts: 3470
Joined: Sun 06 Jan 2008, 23:14
Location: Chickasha Oklahoma
Contact:

#6 Post by puppyluvr »

:D
Close the Windows, and open your eyes, to a whole new world
I am Lead Dog of the
Puppy Linux Users Group on Facebook
Join us!

Puppy since 2.15CE...

Post Reply