Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A meditation reminder app when I'm using the computer
# This Python file uses the following encoding: utf-8
import subprocess
import time
breathing_time = 30 # seconds
interval_between_breathing = 25 * 60 # seconds
applescript = """
display dialog "Breathe and make a home of your body" ¬
with title "Breathe" ¬
with icon caution ¬
buttons {"OK"}
"""
def ding():
subprocess.call("afplay /System/Library/Sounds/Glass.aiff", shell=True)
while True:
idle_time = int(subprocess.check_output('ioreg -c IOHIDSystem | egrep "HIDIdle" | egrep -o "\d+"', shell=True)) / 1.0e9 # seconds
if idle_time < 60: # seconds
subprocess.call("osascript -e '{}'".format(applescript), shell=True)
ding()
time.sleep(breathing_time)
ding()
time.sleep(interval_between_breathing)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.