Skip to content

Instantly share code, notes, and snippets.

@joshuacerbito
Last active October 12, 2022 20:45
Show Gist options
  • Save joshuacerbito/afdb962d32fc8c1b6e62c7a4ea60528e to your computer and use it in GitHub Desktop.
Save joshuacerbito/afdb962d32fc8c1b6e62c7a4ea60528e to your computer and use it in GitHub Desktop.
Simple shell script for watching Internet Speed using Ookla's Speed Test CLI

IMPORTANT NOTE: This only works for MacOS!

The speedwatch shell script requires Homebrew. If you don't have it yet, speedwatch will install it for you. It might take a while, but once installed, using speedwatch should be instant.

Installation Instruction

  1. Open your terminal and paste the following lines:
curl https://gist.githubusercontent.com/joshuacerbito/afdb962d32fc8c1b6e62c7a4ea60528e/raw/speedwatch -o speedwatch
chmod +x speedwatch
mv ./speedwatch /usr/local/bin/speedwatch
echo "Speedwatch has been downloaded! Simply run \"speedwatch\" to start"
  1. Still on your teminal. Type speedwatch and press enter/return
  2. An EULA prompt will be displayed. Type YES and press enter/return
  3. DO NOT close your terminal while the speedwatch is running. Just keep it running in the background.

Stopping Speedwatch

  • Go back to your terminal and press Ctrl+C.
  • You can now close your terminal.

Technically, you can simply close your terminal to stop speedwatch, but it's better to terminate the program first.

#!/usr/bin/env bash
function INSTALL_BREW {
echo "πŸ€·πŸΌβ€β™‚οΈ You don't have Homebrew installed on your computer!"
echo "πŸ“¦ Installing Homebrew now"
echo "⏳ This might take a while..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
}
function INSTALL_SPEEDTEST {
echo 'πŸ“¦ Speedtest is not installed. Installing now... πŸ“¦'
brew tap teamookla/speedtest
brew update
brew install speedtest --force
}
function SHOW_INSTRUCTIONS {
clear
echo "πŸŽ‰ Speedwatch is now installed! πŸŽ‰"
echo "✨ Doing initial speedtest... ✨"
speedtest
echo ""
echo "You're all set!"
echo "Simply run \"speedwatch\" to turn on the Speed Test notifications.";
}
function DO_CHECK {
clear
echo "βŒ›οΈ Checking Internet Speed βŒ›οΈ ($(date)) βŒ›οΈ"
RAW=$(speedtest)
SPEED=$($RAW | grep -E 'Download|Upload')
/usr/bin/osascript -e "display notification \"$SPEED\" with title \"Speedwatch ($(date))\" sound name \"submarine\""
clear
echo "βœ… Your Internet Speed as of $(date) βœ…"
echo "$RAW"
}
function POST_CHECK {
echo ""
echo "Next test will be after $INTERVAL seconds"
}
function START_TEST {
clear
echo 'How often do you want to do a speed test (in seconds)? [default: 3600]?'
read INTERVAL
if [ $INTERVAL -z ]
then
INTERVAL=3600
fi
DO_CHECK
POST_CHECK
while sleep $INTERVAL;
do
DO_CHECK
POST_CHECK
done
}
# PROGRAM START
if brew ls --versions myformula > /dev/null
then
INSTALL_BREW
INSTALL_SPEEDTEST
SHOW_INSTRUCTIONS
else
if [ $(command -v speedtest) -z ]
then
INSTALL_SPEEDTEST
SHOW_INSTRUCTIONS
else
START_TEST
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment