Skip to content

Instantly share code, notes, and snippets.

@marceliwac
Created July 9, 2019 13:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marceliwac/a558301ce5e8e81aaed602be122e66df to your computer and use it in GitHub Desktop.
Save marceliwac/a558301ce5e8e81aaed602be122e66df to your computer and use it in GitHub Desktop.
MacOS WiFi signal-strength meter
#!/bin/bash
#
# Authored by: Marceli Wac
#
# MacOS utility used for displaying the signal strength in a form of cascading progress bar
# prepended with a percentage value. Signal strength is expressed using cubic formula for
# conversion between dBm and % as described in http://cecas.clemson.edu/linux/nm-ipw2200.shtml
# Progress bar should be used for indication only.
# Uncertainty progress bar: +/- 2%
# percentage value: +/- 1%
clear
LOWER_WIFI_BAND=-92
UPPER_WIFI_BAND=-21
SIGNAL_PERCENTAGE=0
while x=1
do
SIGNAL=`/System/Library/PrivateFrameworks/Apple*.framework/Versions/Current/Resources/airport -I \
| grep CtlRSSI \
| sed -e 's/^.*://g'`
if [[ "$SIGNAL" -lt "$LOWER_WIFI_BAND" ]]; then
SIGNAL_PERCENTAGE=0
else
if [[ "$SIGNAL" -gt "$UPPER_WIFI_BAND" ]]; then
SIGNAL_PERCENTAGE=100
else
SIGNAL_PERCENTAGE=$(( ((-154*SIGNAL*SIGNAL)-(3794*SIGNAL)+981820) / 10000 ))
fi
fi
printf "%d%s " $SIGNAL_PERCENTAGE "%"
for i in {0..50}
do
if [[ "$i" -lt $(($SIGNAL_PERCENTAGE/2)) ]]; then
printf "O"
else
printf "-"
fi
done
printf "\n"
sleep 0.5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment