LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 04-05-2004, 07:52 PM   #1
mooreted
Member
 
Registered: May 2003
Posts: 598

Rep: Reputation: 30
Really Cool BlackBox Trick!


I got tired of editing my BB theme script every time I wanted to change the background so I edited the script to always use ~/bkg.jpg. Now, whenever I want to change the background, all I have to do is copy any image to ~/bkg.jpg and the background is changed. Easy!

Ted.
 
Old 04-05-2004, 11:32 PM   #2
gnu noob
Member
 
Registered: Mar 2003
Location: CO
Distribution: Slackware 14
Posts: 138

Rep: Reputation: 15
yeah, that works pretty well, but I'd like to get my hands on a background randomizer that would rotate backgrounds every logon or every day or whatever.
 
Old 04-06-2004, 10:07 AM   #3
mooreted
Member
 
Registered: May 2003
Posts: 598

Original Poster
Rep: Reputation: 30
Yeah, that would be pretty cool. If you run across one let us know.

Later,
Ted.
 
Old 04-06-2004, 11:43 AM   #4
TyphoonMentat
 
Registered: Aug 2003
Posts: 73

Rep: Reputation: 15
Simple enough, have bkg.jpg as a symlink to an image, and delete and change the symlink every day to another file in that directory.
In perl, e.g.

#!/usr/bin/perl
sub random_int_in ($$) {
my($min, $max) = @_;
# Assumes that the two arguments are integers themselves!
return $min if $min == $max;
($min, $max) = ($max, $min) if $min > $max;
return $min + int rand(1 + $max - $min);
}
unlink "bkg.jpg";
@images = split("\n", `ls -1 /home/images`);
$pic = random_int_in(1, $images);
system("ln -s /home/images/$images[$pic] /home/user/bkg.jpg");

Run that with a cron job every day.
 
Old 04-06-2004, 11:49 AM   #5
mooreted
Member
 
Registered: May 2003
Posts: 598

Original Poster
Rep: Reputation: 30
Cool. I have got to learn Perl one of these days.

Thanks for the script.

Have a good day.

Ted.
 
Old 04-06-2004, 12:12 PM   #6
TyphoonMentat
 
Registered: Aug 2003
Posts: 73

Rep: Reputation: 15
Hey, I didn't say if it would work or not
You might need to find a Perl guru if it doesn't, it's just something that I hacked together in about a minute, haven't tested it.
 
Old 04-06-2004, 01:18 PM   #7
mooreted
Member
 
Registered: May 2003
Posts: 598

Original Poster
Rep: Reputation: 30
Linux is all about testing things to see if they work. I don't mind testing things out.

Later,
Ted.
 
Old 04-06-2004, 01:27 PM   #8
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
If the blackbox script can take program output as input (like enclosing it in backticks) then you could get perl to randomly choose and image from a directory and output a filename to stdout. In which case you wouldn't NEED a cron job because blackbox would run the script on init.
 
Old 04-06-2004, 01:40 PM   #9
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Code:
#!/usr/bin/perl

@filenames = `ls *.jpg`;

$size = $#filenames;
$random = rand($size);

print STDOUT $filenames[$random]."\n";
If you put that in a file called chooser.pl, make it executable and change the 'rootcommand' line in the ~/.fluxbox/init file (I've tried this only with fluxbox) to
Code:
bsetbg -f `/home/user/chooser.pl`
(changing /home/user/ to whereever you put the script) it will change the image each time you start fluxbox, though I haven't seeded the random number generator so that might make it less random. Try restarting a few times and see if it works for you. Make sure you use backticks in the @filenames line and in the bsetbg line, not apostrophes. Backticks are under the escape key.

ps. this only looks for images in the same folder as the script itself, but to make it look all over the place is not hard.

Last edited by Komakino; 04-06-2004 at 01:44 PM.
 
Old 04-06-2004, 02:13 PM   #10
TyphoonMentat
 
Registered: Aug 2003
Posts: 73

Rep: Reputation: 15
How about:

Code:
#!/usr/bin/perl
@filenames = `ls  $ARGV[0]/*.jpg`;
$size = $#filenames;
$random = rand($size);
print STDOUT $filenames[$random]."\n";
Just give it the directory the files are in as an input, or hard-code it yourself (replace $ARGV[0]). Also, srand is automatically run from Perl 5.004 (might be 5.005, not sure) onwards at the beginning of scripts, so it should be perfectly random.
 
Old 04-06-2004, 02:23 PM   #11
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally posted by TyphoonMentat
How about:

Code:
#!/usr/bin/perl
@filenames = `ls  $ARGV[0]/*.jpg`;
$size = $#filenames;
$random = rand($size);
print STDOUT $filenames[$random]."\n";
Just give it the directory the files are in as an input, or hard-code it yourself (replace $ARGV[0]). Also, srand is automatically run from Perl 5.004 (might be 5.005, not sure) onwards at the beginning of scripts, so it should be perfectly random.
Yeah, so bsetbg `chooser.pl /images`
should randomly choose a file from /images.

Ahh, what teamwork
 
Old 04-06-2004, 03:08 PM   #12
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
am i missing something or is this "trick" just a manual file copy?? that's no trick.. that's a chore...
 
Old 04-06-2004, 03:12 PM   #13
mooreted
Member
 
Registered: May 2003
Posts: 598

Original Poster
Rep: Reputation: 30
It's easier than:

nano /usr/local/blackbox/themes/Cthulain

rootMenu: bsetbg="/home/mooreted/Antra.jpg"

Restart Blackbox.

I also made a simple shellscript so all I have to do is type "icp [filename]" and the background changes.

Seems pretty simple and easy to me.

Last edited by mooreted; 04-06-2004 at 03:15 PM.
 
Old 04-06-2004, 03:37 PM   #14
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally posted by mooreted
It's easier than:

nano /usr/local/blackbox/themes/Cthulain

rootMenu: bsetbg="/home/mooreted/Antra.jpg"

Restart Blackbox.

I also made a simple shellscript so all I have to do is type "icp [filename]" and the background changes.

Seems pretty simple and easy to me.
You realise that the blackbox rc file overrides the theme rc file anyway? You shouldn't be editting Cthulain to change background image, just the blackbox rc file.
 
Old 04-06-2004, 08:44 PM   #15
mooreted
Member
 
Registered: May 2003
Posts: 598

Original Poster
Rep: Reputation: 30
I did not know that. I didn't notice a root command in blackboxrc. I just went back to Slackware and haven't gotten BB installed yet so I'll check it out some time today.

Thanks for the help.

Ted.
 
  


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
Trick Yum volvogga Linux - Newbie 4 08-18-2005 06:53 PM
Cool Trick - Run all 5 cds from HD (9.2 Pro) apachedude SUSE / openSUSE 14 01-07-2005 01:00 AM
Cool screen blank trick Darin Slackware 2 01-20-2003 09:07 AM
A very cool trick for KDE MasterC Linux - General 22 09-20-2002 12:26 PM
How to trick a router Citizen Bleys Linux - Networking 4 01-31-2002 02:09 PM

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

All times are GMT -5. The time now is 12:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration