Skip to content

Instantly share code, notes, and snippets.

@cdw9
Created March 4, 2020 17:28
Show Gist options
  • Save cdw9/02721aab6c2aa7c04d70e02f935abcd5 to your computer and use it in GitHub Desktop.
Save cdw9/02721aab6c2aa7c04d70e02f935abcd5 to your computer and use it in GitHub Desktop.
Mac daily reminder with Python, Arrow, and a cronjob!
1. Install terminal-notifier: https://github.com/julienXX/terminal-notifier
2. Create a virtualenv
3. pip install arrow
4. test code with `env/bin/python daily-notify.py`
5. Set up the cronjob
6. If you want the notifications to be sticky, go to System Preferences > Notifications, and make sure terminal-notifier notifications display as Alerts
# daily reminder at 9am, with full path to virtualenv python and script
0 9 * * * /Users/chrissy/projects/scripts/env/bin/python /Users/chrissy/projects/scripts/daily-notify.py
import arrow
import os
end_date = '2020-04-01'
def notify(title='Notification', subtitle='', message='Alert message here'):
t = '-title {!r}'.format(title)
s = '-subtitle {!r}'.format(subtitle)
m = '-message {!r}'.format(message)
msg = ' '.join([m, t, s])
os.system(f'/usr/local/bin/terminal-notifier {msg}')
end_date_arrow = arrow.get(end_date)
remain = (end_date_arrow - arrow.now()).days
topic = 'figure out an April Fool\'s Prank'
if remain > 2:
notify(title='Reminder!',
message=f'You have {remain} days to {topic}')
elif remain > -1:
notify(title='WARNING!',
message=f'You have {remain} days to {topic}')
else:
notify(title='****OVERDUE****',
message=f'You have {remain} days to {topic}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment