banner
Previous Page
PCLinuxOS Magazine
PCLinuxOS
Article List
Disclaimer
Next Page

A Simple Linux Alarm Clock


by Paul Arnote (parnote)

I doubt many of you are like me, although I'm sure that there are a few. I have no less than seven computers spread throughout the house that remain on 24/7. I'm sure it's a significant factor on my monthly electric bill. Most of those computers are laptops, and as such, the usual configuration with a laptop is that when the computer is turned on, so is the screen.



With one simple command, I can easily turn off the screen on my laptops. Extending that command a bit more, I can create a very simple -- yet effective -- Linux alarm clock. Simply enter the following command in a terminal session to turn off your laptop's screen:

xset dpms force off

When you hit the "Enter" key, your laptop's screen will be turned off. Don't despair. The screen will come on automatically again when you strike a key, wiggle your mouse or touch your touchpad.

You can create a simple bash script to perform this for you with just a double click of your mouse. Here's my take on it:

#! bin/bash

sleep 15
xset dpms force off

Why the sleep command? Well, to give you a few seconds to take your hands off of the mouse and keyboard, of course, before executing the command. This may be rather important, since without it, the command will be executed immediately and a keypress or mouse wiggle will cause it to turn the screen back on. Simply create the bash file on your desktop, and don't forget to mark it as an executable file. Now, a double click on the file with your mouse will blank your screen in 15 seconds. Feel free to shorten or lengthen the sleep time value to a value that better suits you and your needs.

As you might imagine, if there's an "off" switch, there's also an "on" switch. As such, the command xset dpms force on is the counterpart of the command that turns your screen off. This is what we'll use to create our "Simple Linux Alarm Clock."

If you want to keep it simple and have it only turn on your screen at a certain time, then it's only a simple matter of executing the "on" command as a crontab job. But just turning on the screen isn't enough to wake most of us from a peaceful slumber.

Many of the various desktop environments under PCLinuxOS have some sort of utility that takes the pain out of having to setup and format a cron command by hand. Under Xfce, I use Gnome Schedule, which provides an easy to use and easy to understand GUI for scheduling tasks. It will run under any desktop, and doesn't pull in a bunch of Gnome dependencies (in fact, if I remember correctly, it doesn't pull in any additional Gnome dependencies). VCron, a.k.a. Visual Cron, is also in the PCLinuxOS repository. It will also run under any desktop environment.

To become a "real" alarm clock, we need some sort of sound to be played as well. For my example, I've chosen seven of my favorite Beatle's songs. Hey, I can hardly think of anything better to wake up to. At any rate, I've combined them all into a *.m3u playlist, so all seven songs are played when my "alarm" goes off. Enter your command for the crontab job, like this:

xset dpms force on; play -v 1.0 /home/parnote-toshiba/Music/beatles.m3u

The -v 1.0 part of the play command will play the file at full volume. If that isn't loud enough for you (I hope you have your laptop's volume turned up), you can set the volume to 1.5 (150% full volume) or 2.0 (double full volume). Just don't blame me if you do that and blow out your laptop's speakers.

If you ever get tired of hearing the same songs over and over again every morning, simply create a new playlist (*.m3u file), and change your crontab command to point to the new playlist. Just be sure you provide the full path statement to your playlist file, or you'll be greeted with nothing but silence -- which isn't too effective for an alarm clock.

To be sure you have the command entered correctly, try it out in a terminal session before entering it as your crontab command. If it works on the command line, it will work as your crontab command.

Of course, the added bonus benefit of using this "simple Linux alarm clock" is that there is NO snooze button, so to shut it up/off, you will need to get up and out of bed. This will help improve the chances of you getting/waking up when you should/need.



Previous Page              Top              Next Page