Last Updated: February 25, 2016
·
432
· mcappadonna

Be notified for content in a website

Sometimes it's really usefull to be notified when a specific word (or regexp) is appear on a website.
On Mountain Lion there is a quick method to do that.

First of all, install this tool:

$ sudo gem install terminal-notifier

After that, you can create this bash script:

#!/bin/bash

usage () {
    echo
    echo "usage: $0 <url> <string> <title> <message>"
    echo
    echo "   url     The URL to check"
    echo "   string  The string (or regexp) to check"
    echo "   title   The title of the notification"
    echo "   message The message to display"
    echo
}

[ $# -ne 4 ] && usage && exit 1

URL="$1"
CHECK="$2"
TITLE="$3"
MESSAGE="$4"

wget -O- "$1" 2>/dev/null | egrep -i "$CHECK" &>/dev/null
[ $? -eq 0 ] && terminal-notifier -message "$MESSAGE" -title "$TITLE" -execute "open \"$URL\"" &>/dev/null

exit 0

Now, schedule in your crontab this script with the necessary parameters and voilà, it's done.

$ checkUrl.sh http://digg.com "star wars" "Darth Fener" "Luke, I'm your father. And there is an article about me on DIGG"

Now when the string "star wars" it's found on digg.com, you receive this message:

Picture

Enjoy