Odin Dutton

Barefoot Web Developer @ Locating...

23ba97f

AnyBar Internet Status

by Odin Dutton

AnyBar is a small indicator for your menubar that does one simple thing: it displays color dot. What color means is up to you. When to change color is also up to you.

Knowing when your internet drops out before you open your browser and work it out for yourself can be very handy.

When I first heard about AnyBar that was the first use case I thought of.
I wrote a simple script using host to check if my computer can access Google to keep an eye on my connection status.

Put the following script somewhere on your machine an chmod +x it.

~/bin/anybar-internet

quit() {
  echo -n question | $ANYBAR
  exit
}

trap quit EXIT

ANYBAR="nc -4u -w0 localhost 1738"

while true; do
  if ping -c 5 -t 5 -o 8.8.8.8 &> /dev/null; then
    echo -n black | $ANYBAR
    sleep 5
  else
    echo -n red | $ANYBAR
  fi
done

I decided to keep it running in the background using launchd (tutorial).

Replace $USER with your username and put it in ~/Library/LaunchAgents/:

~/Library/LaunchAgents/com.twe4ked.anybar-internet.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.twe4ked.anybar-internet</string>
	<key>Program</key>
	<string>/Users/$USER/bin/anybar-internet</string>
	<key>KeepAlive</key>
	<true/>
</dict>
</plist>

Launch anybar-internet:

launchctl load ~/Library/LaunchAgents/com.twe4ked.anybar-internet.plist

Stuck? Try me on Twitter: @twe4ked.