Welcome, guest | Sign In | My Account | Store | Cart

An alarm beeping on you when the eggs are boiled.

Python, 57 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python

"""
Beep on me in a while.

Command line utility to shedule an alarm in a specified number of
minutes.

Need `beep <https://github.com/johnath/beep/>`_ on a GNU/Linux system.

    usage: alarm [-h] [-b "<options>"] [-a] number

    Beep-alarm in some minutes

    positional arguments:
      number                Number of minutes until alarm.

    optional arguments:
      -h, --help            show this help message and exit
      -b "<options>", --beep-options "<options>"
                            The options to provide to the beep command. See man
                            beep. Default: "-l 200 -d 50 -r 5"
      -a, --asynch          If given - start beep in the background

"""
import argparse
import os

description = ('Beep-alarm in some minutes')

parser = argparse.ArgumentParser(description=description)

boptsdef = '-l 200 -d 50 -r 5'

parser.add_argument('-b', '--beep-options', metavar='"<options>"',
                    dest='beep_opts', default=boptsdef,
                    help=('The options to provide to the beep command. '
                          'See man beep. Default: "' + boptsdef + '"'))

parser.add_argument(dest='minutes', metavar='number', type=float,
                    help=('Number of minutes until alarm.'))

parser.add_argument('-a', '--asynch', dest='asynch', action='store_true',
                    help='If given - start beep in the background')

args = parser.parse_args()

print 'minutes =', args.minutes
print 'beep_opts =', args.beep_opts
print 'asynch =', args.asynch

ms = str(args.minutes * 60000)
bg = ''
if args.asynch:
    bg = ' &'

os.system('beep -l 0 -D ' + ms + ' --new ' + args.beep_opts + bg)

I need something very simple to get me reminded I have been sitting too long at the computer and need a break. And so I installed beep, really sweet, but I was lacking the possibility to schedule the beep for later and wrote this.

3 comments

Dan Zemke 7 years, 1 month ago  # | flag

FYI, the os.system call to beep will not work on Windows.

On windows, you could #import winsound and then call winsound.Beep(frequency, ms). A reasonable value for "frequency" is 2500 and "ms" is as you already have it defined it in your code.

Tomas Nordin (author) 7 years, 1 month ago  # | flag

@ Dan Zemke: I know, and I see now that my comment on that is not clear enough, thanks. Worse still, it might not work on a Gnu/Linux system with beep installed. beep has wordings on possible problems in the man page, but it didn't help me on my laptop. Very strange.

Vasudev Ram 6 years, 12 months ago  # | flag

Here is one by me:

A simple alarm clock in Python (command-line):

http://jugad2.blogspot.in/2013/11/a-simple-alarm-clock-in-python-command.html