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, b…


This content originally appeared on DEV Community and was authored by Code Ripper

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") + '"')

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

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
$

That's it!

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

How cool is that!

See ya!


This content originally appeared on DEV Community and was authored by Code Ripper


Print Share Comment Cite Upload Translate Updates
APA

Code Ripper | Sciencx (2021-09-11T16:51:06+00:00) Sense of time.py. Retrieved from https://www.scien.cx/2021/09/11/sense-of-time-py/

MLA
" » Sense of time.py." Code Ripper | Sciencx - Saturday September 11, 2021, https://www.scien.cx/2021/09/11/sense-of-time-py/
HARVARD
Code Ripper | Sciencx Saturday September 11, 2021 » Sense of time.py., viewed ,<https://www.scien.cx/2021/09/11/sense-of-time-py/>
VANCOUVER
Code Ripper | Sciencx - » Sense of time.py. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/11/sense-of-time-py/
CHICAGO
" » Sense of time.py." Code Ripper | Sciencx - Accessed . https://www.scien.cx/2021/09/11/sense-of-time-py/
IEEE
" » Sense of time.py." Code Ripper | Sciencx [Online]. Available: https://www.scien.cx/2021/09/11/sense-of-time-py/. [Accessed: ]
rf:citation
» Sense of time.py | Code Ripper | Sciencx | https://www.scien.cx/2021/09/11/sense-of-time-py/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.