Skip to content

Instantly share code, notes, and snippets.

@aniline
Created April 19, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aniline/bfa66d20fbcb704aa4de944eed22d0e4 to your computer and use it in GitHub Desktop.
Save aniline/bfa66d20fbcb704aa4de944eed22d0e4 to your computer and use it in GitHub Desktop.
Notification pop-up timer.
#!/usr/bin/env python
import time
import getopt
import sys
import subprocess
from gi.repository import Notify
def do_notify(message, sleep_s):
try:
Notify.init("Quick Timer")
notify = Notify.Notification.new("Timer", "Elapsed: "+message, "dialog-information")
time.sleep(sleep_s)
notify.show()
subprocess.call(["/usr/bin/aplay", "-q", "/usr/share/sounds/purple/alert.wav"])
except Exception, e:
print "Error: ", e
def do_message(message, sleep_s):
print "Timer `", message, "' for", sleep_s, "seconds."
def do(args, action=None):
message = "Timer elapsed."
if len(args) < 2:
print "timer <time in seconds>"
sys.exit(1)
try:
_sleep = int(args[1])
if len(args) > 2:
message = ' '.join(args[2:])
if action:
action(message, _sleep)
except Exception, e:
print "Error: ", e
if __name__ == "__main__":
if (sys.argv[-1:][0] == "real"):
do(sys.argv[:-1], do_notify)
else:
do(sys.argv, do_message)
subprocess.Popen(sys.argv+["real"],close_fds=True).pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment