Network Bandwidth widget screenshot

Script

Network Bandwidth

by Wayne Folta

Run Apple’s networkQuality script on a regular basis to run a network bandwidth test. It doesn’t run the test if your lid is closed, but I am still experimenting if other gates would be useful (on my home WiFi, not asleep, etc). The idea being, since this uses the network, you don’t want it to keep your Macbook Pro awake, or to fire off while it’s in your backpack.

Script (widget-networkQuality.sh)

#!/bin/bash
set -euo pipefail

# Use full paths because this will be run by cron

lid="$(/usr/sbin/ioreg -r -k AppleClamshellState -d 4 | /usr/bin/awk -F= '/"AppleClamshellState"/ { gsub(/[ "]/, "", $2); print $2 }')"

# No clamshell key on a desktop, so testing "Yes" will correctly treat a desktop as open
if [[ "${lid}" == "Yes" ]]; then
        exit 0
fi

{ printf 'Network Quality: %s\n' "$(date '+%Y-%m-%d %H:%M')"
  /usr/bin/networkQuality -s | /usr/bin/tail -n +2
} | /Applications/TerminalWidget.app/Contents/MacOS/TerminalWidget --target widget1 --fit-text --text -

Download script

← All recipes