Created
April 19, 2018 14:56
-
-
Save aniline/bfa66d20fbcb704aa4de944eed22d0e4 to your computer and use it in GitHub Desktop.
Notification pop-up timer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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