Skip to content

Instantly share code, notes, and snippets.

@madprops
Last active July 20, 2022 08:28
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 madprops/b3cfbdc67a78e8c334cc1ccc9fd44f52 to your computer and use it in GitHub Desktop.
Save madprops/b3cfbdc67a78e8c334cc1ccc9fd44f52 to your computer and use it in GitHub Desktop.
Start a timer using rofi
#!/usr/bin/env python
import re
import os
from sys import argv
from subprocess import Popen, PIPE
# Get input information using rofi
def get_input(prompt: str) -> str:
proc = Popen(f"rofi -dmenu -p '{prompt}'", stdout=PIPE, stdin=PIPE, shell=True, text=True)
return proc.communicate()[0].strip()
# Main function
def main() -> None:
if (len(argv) >= 2):
a = " ".join(argv[1:])
else:
a = get_input("Enter Time")
n = int(re.sub(r"\D", "", a).strip())
u = re.sub(r"\d", "", a).strip()
if u == "m" or "min" in u:
t = n
elif u == "s" or "sec" in u:
t = n / 60
elif u == "h" or "hour" in u:
t = n * 60
else:
t = n
os.popen(f"awesome-client 'timer({t})'").read()
# Program starts here
if __name__ == "__main__": main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment