Skip to content

Instantly share code, notes, and snippets.

@r3a1d3a1
Last active June 11, 2023 23:35
Show Gist options
  • Save r3a1d3a1/0dace5af94480282fdcbfd705bb16f92 to your computer and use it in GitHub Desktop.
Save r3a1d3a1/0dace5af94480282fdcbfd705bb16f92 to your computer and use it in GitHub Desktop.
Idle Notifier (chmod +x IdleNotifier.py)
#!/usr/local/bin/python3
import os, time
from datetime import datetime
period = 3*60
due = period - 5
while True:
idleSecs = round(float(os.popen("ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'").read().splitlines()[0]),0)
if idleSecs >= due and idleSecs < period:
print(datetime.now(), '\tNotifying', flush=True)
os.system(f"/usr/local/bin/terminal-notifier -message 'Shake it!'")
time.sleep( 5 )
else:
secs = due - idleSecs if idleSecs < due else due
print(datetime.now(), '\tSleeping for', secs, 'seconds', flush=True)
time.sleep( secs )
#!/bin/sh
# Idle Monitor Status
pgrep -fil IdleNotifier.py >/dev/null
# Idle Monitor Toggle
pkill -fil IdleNotifier.py >/dev/null 2>&1 || nohup ./IdleNotifier.py >/dev/null 2>&1 & disown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment