Countdown Script

I’m writing the Canadian licensing exam at the end of April, and wanted a wee reminder every morning about the looming deadline.

TL;DR – Schedule a daily countdown script to receive Pushover notification

I have been using Pushover as a unified place to get my custom notifications on iPhone/iPad/Mac. Unfortunately, it is a paid app: after a 7-day free trial, it costs $4.99 USD once, per-platform (iOS, Android, Desktop)

What’s nice about Pushover is that it has good documentation/API and you can trigger notifications via email or a variety of scripts. Here’s the one I use: 

#!/bin/bash

curl \
  -F "token=YOUR TOKEN" \
  -F "user=YOUR USER KEY" \
  -F "message=$1" \
  -F "device=$2" \
  -F "title=$3" \
  -F "url=$4" \
  -F "url_title=$5" \
  -F "priority=$6" \
  -F "timestamp=$7" \
  -F "sound=$8" \
  https://api.pushover.net/1/messages.json

#Usage: sh pushover.sh "message" "device" "title" "url" "url_title" "priority" "timestamp $(date +%s)" "sound"

#token (required) - your application's API token
#user (required) - the user key (not e-mail address) of your user (or you), viewable when logged into the dashboard
#message (required) - your message

#Some optional parameters may be included:
#device (optional) - your user's device identifier to send the message directly to that device, rather than all of the user's devices
#title (optional) - your message's title, otherwise uses your app's name
#url (optional) - a supplementary URL to show with your message
#url_title (optional) - a title for your supplementary URL
#priority (optional) - set to "1" to display as high-priority and bypass quiet hours, or "-1" to always send as a quiet notification
#timestamp (optional) - set to a Unix timestamp to have your message show with a particular time, rather than now
#sound (optional) - set to the name of one of the sounds supported by device clients to override the user's default sound choice

 

This AppleScript:

set today to current date

set theEvent to "MCCQE Part I" -- change this to the event you're counting down to

set diffSeconds to (((date ("May 2, 2017" as string)) - (date (today as string)))) -- change the date here to the date of your event


set diffTotalDays to round (diffSeconds / (86400)) rounding up
set diffWeeks to round (diffTotalDays / 7) rounding down
set daysindiffWeeks to diffWeeks * 7
set remainingDays to (diffTotalDays - daysindiffWeeks)

--more than one week
if diffWeeks > 1 then
	--x weeks and y days
	if remainingDays > 1 then
		set theMessage to "" & diffWeeks & " weeks and " & remainingDays & " days until " & theEvent
	end if
	--x weeks and 1 day
	if remainingDays = 1 then
		set theMessage to "" & diffWeeks & " weeks and " & remainingDays & " day until " & theEvent
	end if
	
	--x weeks
	if remainingDays = 0 then
		set theMessage to "" & diffWeeks & " weeks until " & theEvent
	end if
end if

--exactly one week
if diffWeeks = 1 then
	--1 week and y days
	if remainingDays > 1 then
		set theMessage to "" & diffWeeks & " week and " & remainingDays & " days until " & theEvent
	end if
	
	--1 week and 1 day
	if remainingDays = 1 then
		set theMessage to "" & diffWeeks & " week and " & remainingDays & " day until " & theEvent
	end if
	
	--1 week
	if remainingDays = 0 then
		set theMessage to "" & diffWeeks & " week until " & theEvent
	end if
end if

--less than one week
if diffWeeks = 0 then
	--y days
	if remainingDays > 1 then
		set theMessage to "" & remainingDays & " days until " & theEvent
	end if
	--1 day
	if remainingDays = 1 then
		set theMessage to "" & remainingDays & " day until " & theEvent
	end if
	--the day
	if remainingDays = 0 then
		set theMessage to "" & theEvent & "!"
	end if
end if


set theScript to ("/path/to/pushover.sh " & "'" & theMessage & "'")
do shell script theScript

 

Finally, schedule the AppleScript with Cronnix to run daily at whatever time you choose.

Here’s the end result:

IMG_0317

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s