LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-20-2007, 03:56 PM   #1
cvelasquez
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Rep: Reputation: 15
KDE Random wallpaper or script to create symbolic links to random files


I see KDE is able to make slideshows with an interval before changing a wallpaper to a random one from a list. I want it to select random wallpapers every time it starts, and remain with that picture until the system is rebooted, but I just can't find any option and setting the slideshow interval to 0 just makes a 1 minute interval (and setting a high value is not a solucion, since I don't know how much time the PC will be on). Besides, I don't want to import ALL the wallpapers I want to use, in different directories, so I'd appreciate a PERL script (or something like that) that changes a symbolic link to a random file selected from a list of paths (I can't do it, if you can help me with BASH it would be great, is a scripting language I know and use very much), I haven't find anything.
 
Old 02-25-2007, 07:00 AM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I think the script below does the sort of thing you want. This script uses a separate file with the list of possible symlink targets, but it illustrates how to use bash's built in variable $RANDOM to do the selection.

$RANDOM is automatically seeded when bash is invoked by (I believe) the sum of the system time and the PID. I imagine this is good enough for your purposes. If you wanted to get fancier, you could either seed $RANDOM using /dev/urandom or use the output of /dev/urandom (one or two bytes worth, probably) directly for your random number.

As the comments indicate, I wasn't trying to anticipate all possible faults or allow for a fancy $TARGETS file, so feel free to flesh it out as you wish. And of course, change the definitions of TARGETS and LINK to suit your needs.

Code:
#!/bin/sh

#  Script to randomly select a line from the $TARGETS file as the target
#  for a symbolic link named $LINK.

#  $TARGETS must contain one valid path/file (no spaces) on each line with
#  no other lines present.

#  This is a quick-n-dirty script with almost no sanity testing or decent
#  error reporting.

LINK=/tmp/test_sym_link
TARGETS=/tmp/test_dest

set -e

[ ! -s $TARGETS ] && exit

count=$(cat $TARGETS | wc -l | tr -d " ")
[ $count -eq 0 ] && exit

index=$((($RANDOM % $count) + 1))
dest=$(head -n $index $TARGETS | tail -n 1)

[ "$1" == -v ] && echo "Creating symlink $LINK -> $dest"
ln -sf $dest $LINK
In case I wasn't clear, the $TARGETS file has the following form:

Code:
/home/user/wallpaper/file1
/home/user/wallpaper/file2
/home/user/wallpaper/file3
/home/user/wallpaper/file4
/home/user/wallpaper/file5
 
Old 02-26-2007, 06:48 PM   #3
cvelasquez
LQ Newbie
 
Registered: Mar 2006
Posts: 21

Original Poster
Rep: Reputation: 15
It works, thanks you a lot, I had no idea how it could be done. Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script? how to rename files in random way? lefty.crupps Linux - Software 16 11-03-2015 02:07 PM
one random wallpaper on startup? newbiesforever Linux - General 4 05-30-2007 12:11 PM
Random Wallpaper doublejoon Linux - General 2 01-11-2006 03:35 PM
random wallpaper changer for linux mlu Linux - Software 1 02-11-2005 11:12 PM
Random wallpaper for gnome?? fedorafreak Mandriva 1 09-07-2004 05:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration