Last active
June 11, 2023 23:35
-
-
Save r3a1d3a1/0dace5af94480282fdcbfd705bb16f92 to your computer and use it in GitHub Desktop.
Idle Notifier (chmod +x IdleNotifier.py)
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/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 ) |
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
#!/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