Alarmclock-CLI v1.1

Stuff that has yet to be sorted into a category.
Message
Author
User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

Alarmclock-CLI v1.1

#1 Post by Pizzasgood »

This is a simple alarm clock for the commandline. It can use your media player to play a song when it goes off, or you can set it to run any command you want. It could play a movie, start a text editor, open a website, or delete a file. Basically, it can do whatever you want at the specified time.

alarmclock-CLI-v1.1.pup
alarmclock-CLI-v1.0.pup
alarmclock-CLI-v0.5.pup

Current version is 1.1.

Code: Select all

Usage: alarmclock-CLI [-t HH:MM]|[-H hour -M minute] [-s|-f song/file] [-a app]
                      [-c] [-q --quiet] [-h] 

  -h  --help  Show this message
  -t          The time for the alarm to go off, in 24-hour format: HH:MM
  -s  -f      The path to the song or file you want the alarm to use
                   default=/usr/share/audio/error.wav
  -a  --app   The application to run when the alarm goes off
                   default=defaultmediaplayer
  -c          Prompts for a custom command
  -q          Causes the alarm to not run any apps

alternate time format:
  -H          The hour you wish for the alarm to go off (in 24-hour time)
  -M          The minute you wish for the alarm to go off
If you provide no app, song, or command, it will default to defaultmediaplayer and /usr/share/audio/error.wav.

examples:

alarmclock-CLI -t 9:55
alarmclock-CLI -t 4:15 -q
alarmclock-CLI -H 17 -M 30
alarmclock-CLI -t 22:00 -a firefox -f http://www.murga-linux.com/puppy/
alarmclock-CLI -t 14:12 -s /root/JukeBox/SimCity/SC2Ktheme.ogg
alarmclock-CLI -t 12:01 -a mplayer -f /mnt/sda7/cartoons/MegasXLR/xlr-intro.mov
alarmclock-CLI -t 15:27 -c
Please type the command and hit enter:
for i in *; do mv "$i" "${i}.file"; done



Original post for version 0.5

This is an alarm clock that runs in a terminal window. It isn't fancy, just something I whipped togeather in under an hour. You type a command like this:

Code: Select all

alarmclock-CLI -H 18 -M 30 -s /root/music/coolsong.mp3
That will set it to start playing coolsong.mp3 at 18:30 (6:30 PM). Yes, you have to use 24-hour time (millitary time). -H is for hour and -M is for minute. -s is for song, NOT second. (If people want seconds also, I can add them. I don't see a need for it though)
-h will display a help message.
-q will make it not play the music.

It doesn't run in the background (yet) or have a fancy gui (yet) or show a count-down. That's why it's version 0.5. It's half done, but entirely usable. It does say how many seconds it will take before it goes off when you set it, though :D

I will augment this when I get the chance, hopefully adding a gui and maybe multi-day support and stuff. I don't have a lot of time, though, so don't hold your breath. If anyone wants to modify this on their own, go ahead. That's the fun of open-source.

Oh, it installs to /usr/local/bin/ and is named alarmclock-CLI, in case you need to find it. I haven't added any uninstall capabilities yet either (it's only a small textfile anyway).

Enjoy!
Last edited by Pizzasgood on Tue 16 Jan 2007, 04:56, edited 3 times in total.

User avatar
Ted Dog
Posts: 3965
Joined: Wed 14 Sep 2005, 02:35
Location: Heart of Texas

Turn on computer cron for atx pwr supply

#2 Post by Ted Dog »

http://tcron.sourceforge.net/
If you hook this up you can have the computer turn on at the time needed.
How to build a costly alarm clock

Nevermore
Posts: 366
Joined: Sat 26 Nov 2005, 14:23
Location: Italy

#3 Post by Nevermore »

hello
i was trying your script on my 2.11 and i found the following problem (i dunno if is only in my lap)
first of all i must say that i am running a script that syncs the time with a timeserver every 5 mins, because puppy time works strangerly with my laptop (usually is twice faster), then assume is 22 and i want the script to wake me up at 9am next morning:
i enter:

Code: Select all

alarmclock-CLI -H 09 -M 00 -s /mymusic.mp3 or a streamer
the result is pretty odd, since the script tells me that the alarm is in 33 hours and 00 minutes (look is exactly 24+9) however the seconds are shown correct..
the strange thing is that yesterday i set up to wake me at 7am
actually he woke me at 3am instead..
but the time in puppy was correct..
so i wonder it was either some problems with the timeserver (like puppy couldn't synch and ran faster, then after the alarm went on it was able to synch, or there was something else more strange..
i did many times today and the alarm seems fine as long as is IN the same day, if in the next one, problems arise..
now is 23.48here and i am waiting for the alarm at 00.15
if it behave strangerly again i will make you know
--
/sbin/Nevermore

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#4 Post by Pizzasgood »

Well, better early than late I guess :|

What it does, is after it calculates the number of seconds, it uses the 'sleep' command to sleep for that long. I don't know how the sleep command works internally. It might decide what time it should be done sleeping and then wakes up (alarm-clock style), but it probably tries to time itself (Out house-timer style). If it uses the latter, re-sycing the clock might not fix it.

As for the computational errors, I'll look into it. I might try running it overnight too, but I'll have to make sure I won't need to reboot during the interval.

One solution would be to re-write it to enter a while loop and check the system time. It could use shorter sleeps to keep it from eating resources, and calculate how long of a sleep is safe. For example, if it has several hours, it can be every ten minutes. When it gets close, it could speed up. Eventually it would have to calculate the exact amount to sleep and follow it with the wakeup (otherwise it would start running in a full-speed while loop).

Another way is to have it run normally, but double-check the time before doing the wake-up. Then it could go back to sleep. That way wouldn't work with slow clocks though, just fast ones.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#5 Post by MU »

I think sleep is not very precise.

You might need a routine, that compares the time-values.
see
date --help

Mark

Nevermore
Posts: 366
Joined: Sat 26 Nov 2005, 14:23
Location: Italy

#6 Post by Nevermore »

it is 00.20 and the alarm still doesn't go on..
seems this time is gonna be late..
ok i went now 15 mins late..
considering i put on only 2 hours ago :p
--
/sbin/Nevermore

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#7 Post by Pizzasgood »

The reported time is the time it will go off, not in how long (that's what the seconds are). I neglected to have it subtract 24 when it goes over :roll:

Hmm.. It also won't let you set it to the same hour as the current one, but several minutes earlier. I'll fix that too.

Well, I guess I'll look into precise-icizing it then. While I'm at it, I'll fix the stupid interface it uses, so you can input times as 18:31 if you like. I wrote the current version very quickly with the intention of returning, then I forgot :roll:
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

Nevermore
Posts: 366
Joined: Sat 26 Nov 2005, 14:23
Location: Italy

#8 Post by Nevermore »

actually pizzas, it works pretty good,
just i changed the mediaplayer line
and opens xmms playing the stream with no problem!
gxins instead NEVER EVER was able to play a stream :D
--
/sbin/Nevermore

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#9 Post by Pizzasgood »

You mean it's accurate now because you used XMMS?

I never realized it before, but if it's set to Gxine or Mplayer, you could also point it to a movie, without having to edit the code. By editing the code, you could easlily set it to run any app with any file or options. I might make the next version have an option to change the command, so you could do it easier.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

marksouth2000
Posts: 622
Joined: Wed 05 Apr 2006, 20:43

Re: Alarmclock-CLI v0.5

#10 Post by marksouth2000 »

Pizzasgood wrote: Yes, you have to use 24-hour time (millitary time)
The 24-hour clock was originally developed during the 19th century for use by the railways to avoid trains turning up 12 hours late or early. The military were relatively late adopters. Most of the world's railways were using 24 hour time before the military even began using clocks. Most orders were of the form "we attack at dawn" until the 20th century.

I notice MU put the Swiss railway clock into Muppy, BTW. Despite the Swiss association with clocks and precision railway time, the leading manufacturers of railway watches and clocks were mostly American and British during the 19th century.

I guess that I'm trying to say: thanks for this useful utility PG.

Cheers,
Mark 8)

Nevermore
Posts: 366
Joined: Sat 26 Nov 2005, 14:23
Location: Italy

#11 Post by Nevermore »

Pizzasgood wrote:You mean it's accurate now because you used XMMS?

I never realized it before, but if it's set to Gxine or Mplayer, you could also point it to a movie, without having to edit the code. By editing the code, you could easlily set it to run any app with any file or options.
unfortunately no
i just noticed that is either early or late. and that gxine doesn't play streams :D
--
/sbin/Nevermore

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#12 Post by muggins »

hey pizzasgood,

were you aware of an xmms alarm plugin? see here:

http://freshmeat.net/projects/xmmsalarm/

http://ubuntu.wordpress.com/2006/01/22/ ... -an-alarm/

Nevermore
Posts: 366
Joined: Sat 26 Nov 2005, 14:23
Location: Italy

#13 Post by Nevermore »

that would be perfect
however the script does something different, runs something at a defined time
doesn't matter if is another program, a sound, a movie, or whatever..
in any case, if someone could make a .pup of the plugin it would be great!
or i can make under ubuntu?
thanks
--
/sbin/Nevermore

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#14 Post by Pizzasgood »

alarmclock-CLI-v1.0.pup

support for time formatted HH:MM, with the -t option
support for time with -H <hour> -M <minute> format
custom application with -a or --app option
song, file, website, whatever, with the -s or -f option (identical)
don't run an app or make noise: -q (why use -q? Maybe to put it in a script:

Code: Select all

...
alarmclock-CLI -H $hour -M $minute -q
<do other stuff here>
...
If you provide no app or file parameters, it will default to defaultmediaplayer and /usr/share/audio/error.wav.

examples:

alarmclock-CLI -t 9:55
alarmclock-CLI -t 4:15 -q
alarmclock-CLI -H 17 -M 30
alarmclock-CLI -t 22:00 -a firefox -f http://www.murga-linux.com/puppy/
alarmclock-CLI -t 14:12 -s /root/JukeBox/SimCity/SC2Ktheme.ogg
alarmclock-CLI -t 12:01 -a mplayer -f /mnt/sda7/cartoons/MegasXLR/xlr-intro.mov


This version also doesn't sleep for the entire period. Instead, it sleeps for periods of 60 minutes, checking and re-calculating the remaining time each between period. When the remaining time is under 30 minutes, it will shorten the period to every minute. When the time remaining is under a minute, it will sleep for the exact amount, then go off.

Hopefully that will keep it more accurate on system's such as Nevermore's.

To modify the interval times for fine-tuning, they are at line 148 of /usr/local/bin/alarmclock-CLI.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
darkerror05
Posts: 276
Joined: Sat 17 Jun 2006, 22:10
Location: Rochester NY, USA

#15 Post by darkerror05 »

nice app works great. But could you add the feature to execute a custom command instead of say just a song? It would e great to use it as also a general automation application. For exaple I want to execute the command "cdplay play 4" when the alarm goes off. Thanks for the great work pizza.
-darkerror

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#16 Post by Pizzasgood »

Okay. I'll do it tonight.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#17 Post by Pizzasgood »

alarmclock-CLI-v1.1.pup
Added the '-c' option, which will make it prompt you for a command to run. This way you can have custom things. It can be anything, and supports parameters and "spacy/file names/like/this". You can add a semicolon to use multiple commands. Essentially, you can write an entire bash program in there.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
darkerror05
Posts: 276
Joined: Sat 17 Jun 2006, 22:10
Location: Rochester NY, USA

#18 Post by darkerror05 »

thanks alot works great as usual. Only one tiny problem(its only grammer)
-q Causes the alarm to run any apps
I believe you ment "run any app" :D
-darkerror

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#19 Post by Pizzasgood »

Nope. I actually meant "-q Causes the alarm to not run any apps". Thanks for pointing that out. It makes the -q option seem rather pointless without the 'not' in there :)
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
yim
Posts: 167
Joined: Sat 01 Sep 2007, 05:24
Location: Blue Ridge Mtns

#20 Post by yim »

pizza, just wondering if you or anyone else has attempted a gui for your alarm clock script, it works like a top for me but sometimes I don't pay attention and botch the console command, just curious.
I'm no programmer but I think this little tool is well worth a gui.

good work

yim

Post Reply