Last active
August 13, 2019 15:52
-
-
Save smartwatermelon/bb6bef7aa9f5d72faa3525da23882f63 to your computer and use it in GitHub Desktop.
days-countdown: generate a png showing the number of days remaining until a specified date
This file contains hidden or 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/bin/env bash | |
| ##### | |
| # usage: just run days-countdown.sh to get a countdown until the default date of October 25 | |
| # or specify "from" (e.g. today) and "to" (your target date) in this terrible, terrible format: | |
| # days-countdown.sh "$(gdate)" "$(gdate -d 25-Dec)" | |
| # result is ~/tmp/days-countdown.png | |
| # the png's text color is the hex interpretation of the three-digit days-remaining number ;) | |
| # I use Geektool to position the png on my desktop, and run the script in crontab every hour: | |
| ## 44 * * * * /Users/andrewrich/Documents/scripts/days-countdown.sh >/dev/null 2>&1 | |
| # | |
| # added terminal-notifier so you get a gentle alert when the script fires; comment that if you don't want it | |
| # | |
| # requires: | |
| # * gdate (brew install coreutils) | |
| # * imagemagick (brew install imagemagick) | |
| # * terminal-notifier (brew install terminal-notifier) | |
| ##### | |
| set -euo pipefail | |
| PATH=/usr/local/bin:/usr/local/sbin:$PATH | |
| THIS=$(basename "$0") || THIS="days-countdown" | |
| THIS_FILENAME="${THIS%.*}" | |
| FROM="${1:-$(gdate)}" | |
| TO="${2:-$(gdate -d 25-Oct)}" | |
| DAYNUM_FROM=$(gdate -d "${FROM}" +%j) | |
| DAYNUM_TO=$(gdate -d "${TO}" +%j) | |
| DAY_DIFF=$((DAYNUM_TO - DAYNUM_FROM)) | |
| DAY_COLOR="#$( printf '%03d' "${DAY_DIFF}" )" | |
| DAY_DIFF_PNG="$HOME/tmp/${THIS_FILENAME}.png" | |
| convert -background transparent -fill "${DAY_COLOR}" -family Monaco -pointsize 72 label:"${DAY_DIFF}" "${DAY_DIFF_PNG}" | |
| terminal-notifier -title "${THIS}" -message "${DAY_DIFF}" -contentImage "${DAY_DIFF_PNG}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment