App to alert if Internet connection is lost

Solution 1:

The following script will alert you when your wireless network no longer has a connection. Though you could modify the script to require a check to locate a specific SSID, the following script simply looks for any wireless network connection. The script can be run via a Launch Daemon (login option preferred) or by simply running the script manually when you decide.

Alert mechanism:

If you do not have a wireless network connection the script will set your volume to be set at its maximum, you will then hear an alert beep and the following phrase "your wireless network has been disconnected".

NOTE: This script contains an internal loop. The loop is designed to sleep for 2 min intervals so as not to constantly beep and verbalize said phrase. This interval can be modified to your liking by modifying the "SLEEP_TIMER" variable found within the script.

ALSO: If you are interested in setting up a Launch Daemon but do not have a lot of experience with Daemons, I recommend using Lingon (was once free but Lingon 3 is $2.99).

Tested on:

  • 10.5.x
  • 10.6.x
  • 10.7.4

Please remember to utilize a testing environment prior to running on your primary environment. Feel free to modify the script in any way that suits you, enjoy.

#!/bin/bash

# MONITOR_SSID set as true will keep a loop going (Loop timer 1 minute delay)

MONITOR_SSID="true"

SLEEP_TIMER="60"

while ( ${MONITOR_SSID} == true ); do

    SSID=$(networksetup -getairportnetwork en1 | sed "s:.*\: ::g" | tr -s "[\n]" "[ ]" | sed 's/.*off.*/OFF/g')

    if [[ ${SSID} == "OFF" ]]; then
        osascript -e 'set volume 10'
        afplay -v 2 /System/Library/Sounds/Sosumi.aiff
        say "Wireless network has been disconected"
    elif [[ ${SSID} != "OFF" ]]; then
        :
    else
        /usr/bin/logger -i Error has occured while 'your_script_name' was attempting to run
    fi

    sleep ${SLEEP_TIMER}

done

Solution 2:

You can use ping -A IP, it will automatically give you a beep when their is any timeout, the reverse of it is ping -a IP which keeps beeping until the any timeout.

Solution 3:

Growl manages this as well as alerts from all manner of other events, including from the many apps which support it, quite well.