LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2004, 11:33 AM   #1
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Rep: Reputation: 30
PERL question about getting input of current root window image


i am trying to write a style for fluxbox that will include a perl program to change the wallpaper every 4 months. what i want to do as the first check is pull the name of the image being used as the current wallpaper and see if it is one of the three listed already. if not then change it to the current months image and go on to the process if so then just go on the the rest of the process.
here is the code so far
Code:
#!/usr/bin/perl

#######################################
#	GET THE SYSTEM TIME IN LOCAL FORMAT			#
#######################################

($sec, $min, $hour, $day, $month, $year, $wday, $yday, $dst) = localtime(time);

#######################################
#				THE BEGINNING					  #
#	NO NOTES CAUSE I DON'T KNOW HOW TO DO THIS	#
#	SECTION.								       #
#######################################

if 
#############	CHECK THE BACKGROUND AND CHANGE TO THE CURRENT MONTH'S BACKGROUND IF NOT ONE OF THE 
#############	ONES ASSOC WITH THE PROGRAM. IF THE WALLPAPER IS ASSOC WITH THIS PROGRAM THEN GO TO 
#############	MINCHECK AND START THE PROCESS OF CHANGING THE WALLPAPER EVERY 4 MONTHS.
}
	&MINCHECK


#######################################
#				SUB MINCHECK					  #
#	COMPAIR THE MINUTES AND SEE IF IT IS ON THE	     #
#	HOUR.  IF NOT SLEEP FOR 60 SECONDS AND CHECK     #
#	AGAIN.  IF SO GO TO SUB TIMECHECK.  THIS IS             #
#	TRYING TO GET EVERYTHING UP TO SYNC WITH THE      #
#	HOUR SO THAT AT HOUR 00 MIN 00 ON DAY 1 OF	    #
#	THE CHANGING MONTH THE WALLPAPER WITH CHANGE#
#######################################
sub MINCHECK{
	if ($min != 00) {
		sleep 60;
	}else{
		&HOURCHECK;
	}
}

#86400 seconds in a 24 hour period
#######################################
#				SUB TIMECHECK					 #
#	THIS SUB IS GOING TO CHECK TO SEE IF THE	       #
#	TIME IS 00:00.  IF SO THEN GO TO CHECKMONTH	    #
#	AND CONTINUE THE PROCESS.  IF NOT SLEEP FOR	   #
#	1 HOUR.										#
#######################################

sub HOURCHECK{
	if ($min == 00)&&($hour == 00) {
		&CHECKMONTH;
	}else{
		sleep 3600;
	}
}

#######################################
#				SUB CHECKMONTH				      #
#	HERE IS WHERE WE START CHECKING THE MONTH	#
#	AND PLACING THE PROPER IMAGE IN THE ROOT	    #
#	WINDOW.  FIRST I DIDN'T CHANGE ANY OF THE	     #
#	$MONTH VALUES SO THEY ARE STILL IN RAW		      #
#	FORMAT (0=JANUARY 1=FEBRUARY ETC...).		         #
#	SO FIRST IF ASKS IF IT THE CURRENT MONTH	        #
#	IS JANUARY THRU APRIL AND IF SO CHANGE THE	     #
#	BACKGROUND TO THE PROPER MONTH'S CALANDER      #
#	IMAGE. IF IT ISN'T JAN - APR SEE IF IT IS	                #
#	MAY - AUG AND CHANGE THE WALLPAPER IF SO.	    #
#	IF ALL ELSE FAILS THEN IT MUST BE SEP -	DEC	        #
#	SO CHANGE THE IMAGE TO THE LAST CHOICE.		     #
#######################################

sub CHECKMONTH {

	if ($month >= 0)&&($month <=3) {
		system ("bsetbg ~/.*box/backgrounds/Jan-Apr.Calendar.jpg")
	}elsif ($month >=4)&&($month <=7){
		system ("bsetbg ~/.*box/backgrounds/May-Aug.Calendar.jpg")
	}else {
		system ("bsetbg ~/.*box/backgrounds/Sep-Dec.Calendar.jpg")
	}
	if (month) {
	}
}
if anyone knows of how to do this or a better logic please let me know. i am doing this mostly for me but now that i got it in my head i would like to know and get this done.
thanks in advance.
 
Old 01-02-2004, 12:35 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
for the life of me i have no idea why on earth you are checking the seconds, then the minutes, then the hours, then the month... that's is just bizarre.... why not just start with the month?? i wouldn't bother with perl either, this is pretty simple stuff, and bash could easily handle this:

xv -root -quit -max wallpaper`date +%m`.jpg

are they seriosuly going to be logged in to fluxbox for so long they will miss an entire season? couldn't be easier really....

another slightly more involved method might be to use a cron job to replace a wallpaper 4 times a year... still OTT in my opinion, but nothing as near mad as your idea! ;-)

Last edited by acid_kewpie; 01-02-2004 at 12:38 PM.
 
Old 01-02-2004, 01:06 PM   #3
joesbox
Member
 
Registered: Feb 2003
Location: hampton va
Distribution: ubuntu
Posts: 502

Original Poster
Rep: Reputation: 30
well the reason i am using perl and not bash is cause i don't know how to write a shell script yet. i keep putting it on my todo list to learn shell scripting but i haven't gotten to it yet. [no sarcasm ment] as far as why i am check the minutes (i am not checking the seconds) i am trying to get this thing in sync with the system. it checks the minutes to until it is at 00 minutes then it will start checking the hours. when it is on 00:00 (the first minute of the day) it will then check the month. when it is on a "change month" it will change the image.
what i was hoping for is that when the person uses my style it they will keep using it for a whole year.
now that i think about it i see what you are talking about. i could just check the month and change the image accordingly. then when the new image is required they could just re-run the style and it will work accordingly but that is against the whole project now. i was hoping for a hands off program that would change the image for the user. like this project http://freshmeat.net/projects/meteos.../?topic_id=962
 
Old 01-02-2004, 02:15 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well if you have the line "RootCommand: xv -root -quit -max wallpaper`date +%m`.jpg" in the style file then it will load the appropriate on each time X is loaded.
 
  


Reply



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
perl input field separator Tinkster Programming 5 10-18-2004 04:08 PM
Current PHP, mySQL project, need some input spectrumver1 Linux - General 0 11-17-2003 10:38 AM
Slackware-current Perl 5.8.1 Package tuxq Slackware 0 10-24-2003 07:37 AM
perl input? andox Programming 1 06-25-2003 05:41 AM
console input in perl! farhanali Programming 7 06-12-2003 02:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:01 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