You are not logged in.
Pages: 1
I guess this is the right place for my question... bash scripting is sort of programming, right?
I need a little script that picks a random image from my wallpaper directory to display when X starts. I've written one that takes a directory as its parameter, puts the files into an array, and picks a random index to display, so the problem is solved, but I'm wondering if there's any other way I might have done it. Just out of curiosity. I couldn't find anything about it when I googled.
Offline
I guess this is the right place for my question... bash scripting is sort of programming, right?
No, it isn't. here is the right place
http://www.linuxquestions.org/questions … ay.php?f=9
I removed my sig, cause i select the flag, the flag often the target of enemy.
SAR brain-tumor
[img]http://img91.imageshack.us/img91/460/cellphonethumb0ff.jpg[/img]
Offline
I guess this is the right place for my question... bash scripting is sort of programming, right?
I need a little script that picks a random image from my wallpaper directory to display when X starts. I've written one that takes a directory as its parameter, puts the files into an array, and picks a random index to display, so the problem is solved, but I'm wondering if there's any other way I might have done it. Just out of curiosity. I couldn't find anything about it when I googled.
Sounds good enough for me. Why do you need to another way? Keep in mind bash is very limited, what you have now may be the only way.
Offline
yeah, that sounds like a resonable solution.
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline
yeah, that sounds like a resonable solution.
In bash +1
BTW what did u use /dev/*random directly or through $RANDOM? just out of curiosity
[My Blog] | [My Repo] | [My AUR Packages]
Offline
Yep it's a pretty good solution. I was just wondering if there was some common idiom I'm not aware of.
I used $RANDOM.
Now, when I start X, I never know whether I'll see flowers, breasts, or unearthly scenery. It's very exciting.
Offline
here, i made this awhile ago
http://www.scottbucking.ca/view/en/2
sorry, the website is still in pretty rough shape
Offline
here's the minimal version of the script just as I thought of it
#!/bin/bash
if [ -z "${1}" ];then
echo "USAGE: $0 <folder>"
exit 1
fi
PROG="feh"
ARGS="--bg-scale"
if ! type "${PROG}" &>/dev/null ; then
echo "${PROG} is not a valid program"
exit 1
fi
# make sure path is absolute
folder="$(cd ${1}; pwd)"
# Build images array
images=($(find ${folder} -name *.jpg -o -name *.png -o -name *.gif))
# Generating a random number from 0 to ${#images[@]}
rand="$(expr $RANDOM % ${#images[@]})"
# Setting wallpaper
${PROG} ${ARGS} ${images[$rand]}
exit $?
Pretty easy and a good idea
[My Blog] | [My Repo] | [My AUR Packages]
Offline
here, i made this awhile ago
http://www.scottbucking.ca/view/en/2
sorry, the website is still in pretty rough shape
You don't need the whole
PICS=$(ls $BGDIR)
numpics=1
for pic in $PICS
do
file[$numpics]=$pic
let "numpics += 1"
done
do
PICS=($(ls $BGDIR))
and numpics will be
${#PICS[@]}
and you don't need
FLOOR=0
RANGE=$numpics
number=0 #initialize
while [ "$number" -le $FLOOR ]
do
number=$RANDOM
let "number %= $RANGE" # Scales $number down within $RANGE.
done
Just take the modulo of $RANDOM divided by the number of images, for instance
number=$(expr $RANDOM % ${#PICS[@]})
P.S: look at my lil script above
[My Blog] | [My Repo] | [My AUR Packages]
Offline
thanks, duly noted
i did it awhile ago when i was learning bash
dont expect it to be too polished
Offline
here's a polished one http://wael.nasreddine.com/files/config … background that I use myself
[My Blog] | [My Repo] | [My AUR Packages]
Offline
Pages: 1