Timer in Terminal

main.py

Python
import sys
import os
import time
from datetime import datetime

def beep():
    os.system('afplay /System/Library/Sounds/Ping.aiff')

def start_timer(duration=25):
    start_time = datetime.now()

    total_seconds = duration * 60
    print(f"Timer started for {duration} minutes.")
    while total_seconds > 0:
        minutes, seconds = divmod(total_seconds, 60)
        print(f"{minutes} minutes {seconds} seconds remaining...")
        time.sleep(10)  # Sleep for ten seconds
        total_seconds -= 10
    end_time = datetime.now()
    activate_terminal()
    print(f"🍅 {duration}m time is up! 🎉")
    print(f"  start: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
    print(f"  end: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")

    beep()

def activate_terminal():
    os.system('clear')  # This clears the Terminal
    os.system("osascript activate_terminal.scpt")

if __name__ == "__main__":
    if len(sys.argv) > 1:
        try:
            duration = int(sys.argv[1])
        except ValueError:
            print("Please provide the duration in minutes as an integer.")
            sys.exit(1)
    else:
        duration = 25  # Default duration is 25 minutes if no argument is provided
    start_timer(duration)

activate_terminal.scpt

AppleScript
tell application "Terminal"
    activate
end tell