Making Linux remind me to meditate

November 27, 2010

When I’m working on my computer, I often lose track of time. In itself I don’t mind this, but the downside is that I often am not aware of the different sandhyas, the different phases of the day (sunrise, noon and sunset) at which I should meditate on the Gayatri mantras I received at initiation.

Luckily, with Linux it is very easy to have your computer remind you that it is nearly time to chant. All you need is crontab and gxmessage. Crontab is part of the default installation of many distributions, and gxmessage is easily installed (. Here is how you would do it.

First of all, you’ll need to create a Gxmessage script. Here is what I use:

#!/bin/sh

gmessage "It is time to chant your Gayatri mantras" -center -title "Take action" -font "Sans bold 7" -geometry 300x100 -default "Remind me later" -center -buttons "_Remind me later":1,"I'll _chant now":2 >/dev/null

case $? in
1)
(sleep 10m && /home/USERNAME/.scripts/Gayatri_gmessage);;

2)
echo "Exit";;

esac

Save the file in a convenient location as (I keep it in ~/.scripts/) as Gayatri_reminder or whatever else you like, and make the file executable with the following command:

chmod +x /home/USERNAME/.scripts/Gayatri_reminder

(Wherever you save it, make sure that the line which reads “sleep 10m && /home/USERNAME/.scripts/Gayatri_gmessage” in the above example points to the location of your script.)

If you’d like to test the script, you should be able to either double click on the file, or to enter the full path to the file in a terminal to launch Gxmessage. The script should launch a window that looks like this (it should follow your general Gtk theme):

If you click “Remind me later” the window will pop up again 10 minutes later; if you click “I’ll chant now” the message will simply close. You can change those settings (including the text that is displayed) by editing the script I gave above.

Now you’ll need to tell your operating system that you want this script to be run every day at noon and at 6pm. To accomplish this, you can use cron and crontab. Cron is a daemon that executes scheduled commands. It is normally started automatically when you start your computer. Crontab is a little application that allows you to add or remove scheduled commands for individual users. To add an entry for your Gayatri reminder message, start crontab in the edit mode with the following command:

crontab -e

If you have never used crontab before, an empty file should open that looks like this:

# m h dom mon dow command

This indicates the structure you need to use for crontab entries: for each entry you can specify the minute (0-59), the hour (0-23, 0 = midnight), the day of the month (1-31),the month (1-12), and the day of the week (0-6, 0 = Sunday), and finally the command you want to be executed at that time. If you want to run a command every day of the month, or every day of the week, you can enter an asterisk (*) as the value to that setting.If you want to cron to launch an application with a graphical user interface, such as Gxmessage, you need to specify what screen to display it on with the command export DISPLAY=:0. If you only have a single screen, you need to use DISPLAY=:0; if you have more than one screen and would like the message to appear not on the first screen change the number accordingly (to :1 or :2).

So if you want this Gxmessage script to be run every day at noon,and at 6pm, you would add two entries in crontab that looks like this:

00 12 * * * export DISPLAY=:0 && /home/USERNAME/.scripts/Gayatri_reminder
00 18 * * * export DISPLAY=:0 && /home/USERNAME/.scripts/Gayatri_reminder

This will run the script every day of every month and every day of the week (the three *s) at 00 minutes past 12 and 18 hours. The command part of each line ( export DISPLAY=:0 && /home/USERNAME/.scripts/Gayatri_gmessage) specifies that the Gayatri_reminder script is to be run on the first screen.

There are some obvious drawbacks to this system. If you want to be very strict and meditate on the Gayatri mantras at the exact sandhya times, this method is not very practical, unless you live close to the equator where the sunrise, sunset and when the sun reaches its zenith are nearly at the same time of day all year round. I started writing a script that took the exact sunset times into consideration, and had some success, but lost that script and can’t be bothered to rewrite it. Maybe I’ll revisit it in the future, but for now this system works fine. I’d rather chant my Gayatri mantras slightly off time, than forget them entirely.

3 Responses to “Making Linux remind me to meditate”

  1. Ben said

    I appreciate the rundown of cronttab and gxmessage, but two things I noticed, one is that the script doesn’t work for me unless i type gxmessage where you have gmessage. Typo aside, there is something more important, you can have a script recurse(rerun) without knowing by what name it was called. Just as $1 is the first argument, $@ is all arguments, and so on, $0 refers to the command. Here’s an example using your script:

    #! /bin/bash
    gxmessage “Called via $0 by `whoami`” -center -title “Proof of Power” -font ‘Sans bold 7’ -geometry 300×100 -center -buttons “_Run again”:1,”Make this go away”:2 >/dev/null

    case $? in
    1)
    (sleep 10 && $0);;

    2)
    echo “Exit”;;

    esac

  2. Very, very nice. I’ve used your script, but I didn’t put it directly into a crontab. I put it into a /etc/cron.hourly. Of course I had troubles… It wasn’t working.

    So I had to add “export DISPLAY” stuff directly into the script, as well as I’ve inserted condition, if X (Fluxbox) are running.

    It was still sending error, so finally I have inserted comand “sudo -u gxmesage…” and your beautiful script started stabbing my lazy bum. (:

    #! /bin/bash

    if ps -ef | grep -v grep | grep “fluxbox” 1> /dev/null
    then
    export DISPLAY=:0 &&

    sudo -u gxmessage $@ ”
    it’s Meditation time ” -center -title “TITLE” -bg “#000000” -fg “#5bd412” -font “Sans bold 36” -geometry 300×100 -buttons “Lazy”:1,”I’m on $

    case $? in
    1)
    (sleep 10 && $@);;

    2)
    echo “Exit”;;

    esac
    else
    echo “fluxbox or X are not running”
    exit
    fi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s