Skip to content

Instantly share code, notes, and snippets.

@rubenhorn
Last active December 17, 2022 12:28
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 rubenhorn/7c065f570e2bb61b8e3ada44ebac4adf to your computer and use it in GitHub Desktop.
Save rubenhorn/7c065f570e2bb61b8e3ada44ebac4adf to your computer and use it in GitHub Desktop.
Personal Push Notifications
#! /bin/sh
HOST="ntfy.sh"
TOPIC="hh2WuvyfG7dN8tQx8ZxLF8wE"
TIMEOUT=10
# Hack to get around issue of output not being piped
while true
do
curl -s $HOST/$TOPIC/json --max-time $TIMEOUT | jq -c 'select(.event == "message")' | while IFS= read -r JSON
do
TITLE="$(echo $JSON | jq -r '.title')"
MESSAGE="$(echo $JSON | jq -r '.message')"
notify-send -a "$HOST/$TOPIC" $TITLE $MESSAGE
done
done
#! /bin/sh
HOST="ntfy.sh"
TOPIC="my-topic"
if [ $# == 1 ]
then
TITLE="ntfy.sh"
MESSAGE="$1"
elif [ $# == 2 ]
then
TITLE="$1"
MESSAGE="$2"
else
echo "Usage: $0 [TITLE] <MESSAGE>"
exit 1
fi
curl -H "Title:$TITLE" -d "$MESSAGE" $HOST/$TOPIC &> /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment