Jump to content
xisto Community
Sign in to follow this  
rob86

Turn Your Linux Into An Alarm Clock ...and maybe learn some other nifty things.

Recommended Posts

Did you know you could quickly and easily turn your computer into an alarm clock with linux? All you need is a few different things, which are probably already installed!

Preliminary step:

Make sure you have SOX - Sound Exchange installed. Type the play command in a terminal, if the command is found, it's installed, if not, install SoX.

sudo apt-get install sox
or get it installed somehow.

Next determine the audio file you wish to play. I'm not sure what formats are supported, but use whatever works for you. I use wav's. If you're not sure what to use, why not browse your drive?

find / -iname '*.wav'

You may be surprised and find a .wav from an application or game that would work well for an alarm. When you find a good alarm clip, make a note of it's path, copy it into a note or clipboard manager.

Now, onto the Alarm.

Method #1 - The recurring alarm.

Let me introduce you to cron. This is the scheduling daemon on linux and can be used to run anything at any time. I won't go into the details of all the many ways to use cron, there are lots of sources on google. I will however show you how to use it to create an alarm.

To edit your crontab, and add something to your computers schedulers, type

crontab -e

This will open up a text editor (Vi, but there are other options like emacs.. google for more information if you prefer this). If you don't know how to use Vi to edit a file, just remember that there are two modes. Edit mode and insertion mode. Push the i key to go into insertion mode which will allow you edit the crontab. Push escape a couple times, then type :wq! to exit and save your crontab.

So what do you put there? If you're lucky, the first line of your crontab is a guide. You simply put the time you want the alarm to occur on the second line.
Check out the letters, they make complete sense when you look at it. m = minute, h = hour, dom = date of month, month = month, dow = day of week. Time is in 24 hour military format. Sunday is 0, Monday is 1..etc
Let's say you want alarm to chime every morning at 7:45am on weekdays, not weekends.. You would add something like this to your crontab.
#m h dom mon dow command45 7 * * 1-5 COMMANDGOESHERE

Now what do you put in the command section? Well, cron can be picky, so you need to find the direct path to SoX. Type in:

which play

Which will give you the path, most likely /usr/bin/play

So back to your crontab, you type in

#m h dom mon dow command45 7 * * 1-5 /usr/bin/play /home/username/myalarm.wav

Replace /home/username/myalarm.wav with the path to your audio clip you saved earlier! And there you go, your alarm should be ready to annoy the heck out of you when you least want it to.


# Method two:

Believe it or not, there's another method. This method is most useful for one-shot reminders that will only occur once. It's called the AT command. It's incredibly simple to use.

Simply type something like this. Don't type the <ENTER> and <CTRL-D> ... just do it.

at 6:00pm tomorrow <ENTER>/usr/bin/play /home/username/dinnertime.wav <ENTER><CTRL-D>

Cool! Your alarm will ring at 6:00pm the next day. Of course, you don't have to put tomorrow in. It's a very flexible command.

-------

Well that's it. These two scheduling commands are of course much more powerful. You don't have to use these commands solely for playing audio, they can do anything! Read the manual for AT and CRON or google for some lessons. You won't regret it!

If you have any questions..feel free to ask. I'll try to help. I probably missed something important.

NOTE: Trying to open up windows or display data can get tricky with these schedulers.. it's not easy and obvious but it's possible. If you're interested, let me know.

Share this post


Link to post
Share on other sites

No offense, but what exactly is the point of this? Wouldn't it be easier to mess with the internals of Linux as least as possible? A background program would be much safer, right?and I DO have a Linux, if you're going to say I understand nothing about Linux.

Share this post


Link to post
Share on other sites

No offense, but what exactly is the point of this? Wouldn't it be easier to mess with the internals of Linux as least as possible? A background program would be much safer, right?
and I DO have a Linux, if you're going to say I understand nothing about Linux.


A lot of people use use Cron to play an audible alarm. It's not something I thought up. I thought it was useful, and it's not just about making an alarm, it's about being introduced to two useful and important parts of Linux. For example, to run something (wvdial to connect to internet for example) on startup, you simply add @reboot /thefile to the crontab. I also use it to weather images regularly. It's frequently used to keep things running in case something crashes, like eggdrop bots being run on a unix shell. Knowing how to use cron and at is in my opinion important knowledge for a linux user and quite within the understanding of anyone, there's not too much difficult or unsafe about it as long as you're reasonably confident using a command line interface. You don't even need to be a SuperUser to use cron. Just because they are built in doesn't mean they are only for unix experts, it means they have proven useful enough to keep installed by default!

I wasn't going to say you understand nothing about Linux. I've only been using Linux a little while myself, I certainly don't consider myself a unixGuru. Just sharing what I learned that I found interesting. I've found that Linux isn't about being easy, it's about being powerful and useful. A lot of the appeal of Linux is power of it's CLI programs, in fact half it's GUI applications seem to be just front ends for popular CL programs. Still, I thought using cron to schedule a task was pretty easy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.