Skip to content

Instantly share code, notes, and snippets.

@JDiPierro
Created January 8, 2020 19:47
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 JDiPierro/b300ae78f4d3ead672bc13b9074f804d to your computer and use it in GitHub Desktop.
Save JDiPierro/b300ae78f4d3ead672bc13b9074f804d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Takes a 24-hour time as the first argument and displays the second argument as a Mac dialog at that time.
# Usage:
# $ timebox 15:00 "Refresh the dashboard"
TARGET="${1}"
if [[ -z "${TARGET}" ]] ; then
echo "You must pass a time as the first argument" >&2
exit 1
fi
MSG="${2}"
if [[ -z "${MSG}" ]] ; then
echo "You must pass message as the second argument" >&2
exit 1
fi
current_epoch=$(gdate +%s)
target_epoch=$(gdate -d "today ${TARGET}" +%s)
sleep_seconds=$(( $target_epoch - $current_epoch ))
echo "Message will be displayed after ${sleep_seconds} seconds."
(
sleep ${sleep_seconds};
osascript -e "tell app \"System Events\" to display dialog \"$MSG\"" >/dev/null
) &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment