Last active
July 20, 2022 08:28
-
-
Save madprops/b3cfbdc67a78e8c334cc1ccc9fd44f52 to your computer and use it in GitHub Desktop.
Start a timer using rofi
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 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