Skip to content

Instantly share code, notes, and snippets.

@danuker
Created March 11, 2026 00:50
Show Gist options
  • Select an option

  • Save danuker/b6d5a7026c42bb8009f78e1b90f084ca to your computer and use it in GitHub Desktop.

Select an option

Save danuker/b6d5a7026c42bb8009f78e1b90f084ca to your computer and use it in GitHub Desktop.
Time waste annoyance
#!/usr/bin/env python3
# If I'm wasting time, pop up an image that reminds me of my addiction.
# Created 2026-03-11
# One-shotted by Qwen3.5-35B-A3B-UD-IQ4_NL from Unsloth
import subprocess
import time
import re
from datetime import datetime
# Configuration
CHECK_INTERVAL = 60 # Check every minute (seconds)
CONSECUTIVE_THRESHOLD = 3 # Matches required in a row to trigger action
# Regex pattern for window titles (case-insensitive by default logic below)
PATTERN_STR = r'www\.youtube\.com|reddit|Facebook|Twitter|Instagram|Threads|substack.com'
regex_pattern = re.compile(PATTERN_STR, re.IGNORECASE)
# Path to the image and viewer command
IMAGE_PATH = "/home/dan/Pictures/reality_1920x1200_by_eranfowler_dfcqms.jpg"
VIEWER_CMD = ["ristretto", IMAGE_PATH]
def get_active_window_title():
"""Retrieves the title of the currently active window using xdotool."""
try:
# Get the ID of the focused window, then get its name/title
cmd = ["/usr/bin/xdotool", "getactivewindow"]
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode != 0:
return None
win_id = result.stdout.strip()
# Get the window name (title) using xdotool getwindowname or wmctrl -lGp to be safe with spaces/special chars
cmd_title = ["/usr/bin/xdotool", "getwindowname", win_id]
title_result = subprocess.run(cmd_title, capture_output=True, text=True)
if title_result.returncode == 0 and title_result.stdout.strip():
return title_result.stdout.strip()
except Exception as e:
print(f"Error getting window name: {e}")
return None
def check_and_launch():
"""Main logic loop."""
consecutive_matches = 0
print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] Starting monitor. Pattern: '{PATTERN_STR}'")
while True:
title = get_active_window_title()
if not title:
# If we can't get a title (e.g., no window focused), reset counter or ignore?
# Let's reset to be safe, as "no window" is not a match.
consecutive_matches = 0
time.sleep(CHECK_INTERVAL)
continue
print(f"[{datetime.now().strftime('%H:%M:%S')}] Active Window: '{title}'")
if regex_pattern.search(title):
consecutive_matches += 1
status = "MATCH"
else:
# Reset counter on non-match to ensure strict "5 times in a row" logic
consecutive_matches = 0
status = "NO MATCH"
print(f"[{datetime.now().strftime('%H:%M:%S')}] Consecutive Matches: {consecutive_matches}/{CONSECUTIVE_THRESHOLD} - Status: {status}")
if consecutive_matches >= CONSECUTIVE_THRESHOLD:
print("\n*** CRITERIA MET! Launching viewer... ***")
try:
# Run the image viewer in the background so it doesn't block this script (optional)
subprocess.Popen(VIEWER_CMD, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except Exception as e:
print(f"Error launching viewer: {e}")
time.sleep(CHECK_INTERVAL)
if __name__ == "__main__":
try:
check_and_launch()
except KeyboardInterrupt:
print("\nScript stopped by user.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment