Skip to content

Instantly share code, notes, and snippets.

@uxjw
Last active February 24, 2019 00:46
Show Gist options
  • Save uxjw/c144b0e9ace489ede6b722ad1850c55d to your computer and use it in GitHub Desktop.
Save uxjw/c144b0e9ace489ede6b722ad1850c55d to your computer and use it in GitHub Desktop.
Hourly announcement with quiet hours
#!/bin/bash
# Announce the current hour
#
# Use cron to schedule this on the hour:
# 0 * * * * /path/to/script/chime.sh
#
# Change the voice used in System Preferences
# under Accessibility > Speech
# Wake up the text-to-speech engine, which sometimes
# misses the first part of text and just says "o'clock"
say " "
sleep 2
# 24-hour time for if statements
HOUR=$(date +%k)
# Silence from 1am through 9am
if [ $HOUR -gt 9 ]
then
# If past noon, use 12-hour format
# AM/PM should be obvious
if [ $HOUR -gt 12 ]
then
HOUR=$(date +%l)
fi
# Announce hour
say "Its " $HOUR " o'clock"
else
# Instead of hour 0, say midnight
if [ $HOUR -eq 0 ]
then
say "Its midnight"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment