Skip to content

Instantly share code, notes, and snippets.

@kylemarsh
Created March 17, 2017 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemarsh/aed3ce045ae38115390ec39810169396 to your computer and use it in GitHub Desktop.
Save kylemarsh/aed3ce045ae38115390ec39810169396 to your computer and use it in GitHub Desktop.
Variable-period notifier for OSX
#!/bin/sh
# Variable-period notifier for OSX
# Requires the following (available via homebrew):
# terminal-notifier (https://github.com/julienXX/terminal-notifier)
# reattach-to-user-namespace (https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)
# See below for information about reattach-to-user-namespace (necessary to connect to notifications via `at`):
# https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard#mac-os-x-pasteboard-access-under-tmux-and-screen
##########
# Log all output to file for debugging
#exec 1<&1-
#exec 2<&1-
#exec 1<>~/logflowers.log
#exec 2>&1
#########
SCRIPT='bin/reminder.sh'
NEXT=`awk 'BEGIN{srand(); printf("%d\n", rand()*60+30)}'` # 30 + (0-60)
TITLE="Remember to do the thing!"
MESSAGE="Next in $NEXT days"
RESULT=`reattach-to-user-namespace terminal-notifier \
-message "$MESSAGE" \
-title "$TITLE" \
-sound "Purr" \
-open "http://www.cnn.com/" \
-actions "Tomorrow" \
-timeout 6` # Customize as you like
case $RESULT in
'@CONTENTCLICKED')
# reschedule for 9am $NEXT days from now if clicked
at -f $SCRIPT 09:00 +$NEXT days
;;
'Tomorrow')
# reschedule for 9am tomorrow if "Tomorrow"
# don't do +1 days because it's already past 9am
at -f $SCRIPT 09:00
;;
'@TIMEOUT')
# reschedule for a few min from now if not clicked after 30s
at -f $SCRIPT now +5 minutes
;;
*)
ac -f $SCRIPT now +5 minutes
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment