Saturday, 19 December 2015

Make yourself a talkin alarm clock on linux :)

Many of you guys, in my opinion, are hardcore Linux fans who spend lots of time browsing new stuffs or just 'making love to' your cute li'l OSes. :) Now, if you're like me, you forget the track of time when you take  deep breath and take a dive into linux. But this often hampers your regular schedule, like taking your dinner in time and getting to watch your favourite TV show. In fact, there have been many days in my life, when I was practically bashing myself out after having missed my favourite documentary or movie.

Now, there are three easy ways I know of, using which you can tell your linux-box to remind you at the time of such events. I know, that there are many GUI apps available for the same purpose, but I still can't resist the idea of a posting about three of these myself.

But at first, you need to install a tiny little app called 'festival', which is basically a tts (text to speech) reader. To install, open your favourite terminal emulator and enter:
sudo apt-get install festival
Once it's installed, you're ready to go. Optionally, you can test your festival installation. To do so, open terminal and type:
echo "Hello, this is your computer speaking to you." | festival --tts
And it everything worked correctly, your computer just spoke to you. :)

Now comes the little bit hard part.

The CUI mode


This needs no extra software. It simply uses a daemon, called cron, which runs in the background. The purpose of this demon is to execute specific commands at specific times. To make a new entry, open a terminal and type exactly:
crontab -e
And a selection of terminal editors will be presented to you. Select Nano editor, as it's by far the easiest.   Now, once the file is opened, it basically looks like:
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
Now, you have to understand the syntax. The best way is to start with an example. Lets say, I always forget to take my tea at 5:45 PM every day except Sundays, and want Cron to remind me. To do so, go to the last line of the file and enter the following line exactly:
30 17 * * 1,2,3,4,5,6 echo "Hey, it's the time for your tea, mate." | festival --tts 
Press Ctrl+X and then y to confirm the changes to the file. Now exit the terminal. Bingo!!
Now, lets understand the matter. What makes cron so useful is its ability to use wildcards. Look at the command carefully. I explain each part of it one by one:

  • 30 - This is the minute. This means 30 minutes past the hour.
  • 17 - This is the hour. 5:00 PM = 17:00
  • * - This is the day of the month. It can be from 1 to 31. If you want to specify the dates on which your command will be executed, you can enter ay value from 1 to 31, or a combination of values. For example, if you want the command to run on 1st, 2nd and 3rd days of every month, enter 1,2,3 in the place of * (separated by commas). * means every day of the month.
  • * - This is the number of the month. This can vary from 1 to 12, i.e Jan to Dec. Well, * again means every month. This determines on which months your command will be executed.
  • 1,2,3,4,5,6 - These are the days of the week on which your command is to be executed. 1 is Monday, 2 is Tuesday and so on. It can vary from 1to 7. I have set it to 1,2,3,4,5,6 so that my command is executed on each day except the 7th day, i.e Sunday. 
  • The next part is your command. Here,
 echo "Hey, it's the time for your tea, mate." | festival --tts 
is the command to be executed. This is acts as a voice reminder. Kinda like Jarvis from Iron Man movies, right? :D

The GUI Mode (easier)


Basically does the same thing, but just uses a simple app without going into the details of diting the crontab file manually. Just install Gnome Scheduler (sudo apt-get install gnome-schedule) and open it. Select 'New task' and you are presented with a nice and simple menu. Select 'A recurrent task' and give it a name in he 'Description' box. Now, enter exactly the same command
echo "Hey, it's the time for your tea, mate." | festival --tts
in the command box. Select the Advanced radio-button and give the appropriate minute, hour etc. to your command and you're done.

Here are some typical examples of what you can issue as commands. :) You've every liberty to make your system do whatever you want btw.

echo "Hey mate! Breakfast!" | festival --tts
echo "Hey weirdo! It's 9:00 AM! Who's gonna take his bath now?!" | festival --tts
echo "I'll break your neck if you don't get off your chair and take a fresh evening walk!" | festival --tts
echo "Dinner time pal. Suit yourself." | festival --tts

Infinite possibilities.
For any problem or help, please post a commend and I'll try my best to help you. :)

No comments:

Post a Comment