DEV Community

Cover image for Sense of time.py
Code Ripper
Code Ripper

Posted on

Sense of time.py

The trouble is, you think you have time. - Jack Kornfield

This is my first blog, thought of starting with a quote :-).

With work from home being a new normal, we often get distracted by something and lost the track of time. Might Not be everyone, but people like me.

Research studies have proven that A regular reminder of passage of time seems to have a definite good impact on one's efficiency and productivity(don't look it up!)

So I have decided to create a very simple background process that reminds you the time every quarter-hour.

We are going to use python and crontab service in your MacOS.

#!/usr/bin/env python
import os
import time

# Say current time
os.system('say -v Samantha "The time is now ' + time.strftime("%I:%M %p") + '"')
Enter fullscreen mode Exit fullscreen mode

Simple, indeed

As you can see, we have used say-command, which is a CLI for Speech Synthesis Manager. I didn't like the default high-pitched male voice, so I changed to -v Samantha

Put the above python snippet in a file, save it somewhere and copy the file path. In my case, it is ~/dev/scripts/sense_of_time.py

Now, we are gonna use crontab - explained by one of my favourite blogger Ole Michelsen

Open your terminal and run crontab -e to edit the job list. it will be empty, if you don't have any job configured.

We are gonna configure a new job now. Paste the below line in crontab job file,

 */15 * * * * /usr/local/bin/python3 ~/dev/scripts/sense_of_time.py
Enter fullscreen mode Exit fullscreen mode

Explanation:

  1. */15 * * * * - cron expression tells when the job should run. Change this expression if you want it to run at different time interval.
  2. /usr/local/bin/python3 - path of python binary, change it if your path is different
  3. ~/dev/scripts/sense_of_time.py - path of your python file.

Now, save and close the file to install the cronjob, if you are using vim, press ESC, type :wq and hit enter.

you should see

$ crontab -e
crontab: installing new crontab
$
Enter fullscreen mode Exit fullscreen mode

That's it!

When the time is *:15/30/45/00, you will get a voice reminder.

How cool is that!

See ya!

Top comments (0)