Last active
April 12, 2024 14:29
-
-
Save danielbdias/4cd4908cb973003ab69c427b6d8c2ede to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# <xbar.title>Internet check</xbar.title> | |
# <xbar.version>v1.0</xbar.version> | |
# <xbar.author>Daniel Dias</xbar.author> | |
# <xbar.author.github>danielbdias</xbar.author.github> | |
# <xbar.desc>Plugin to check network stability on your Mac.</xbar.desc> | |
# <xbar.image>http://www.hosted-somewhere/pluginimage</xbar.image> | |
# <xbar.dependencies>perl</xbar.dependencies> | |
# Plugin for https://github.com/matryer/xbar | |
# | |
# Based on https://blog.ershadk.com/2020/05/11/how-to-configure-a-simple-internet-status-widget-in-macos-menu-bar.html | |
# Latency threshold in ms | |
LATENCY_THRESHOLD=30 | |
latency=$(ping -c1 8.8.8.8 -t 2 | \ | |
perl -n -e'/time=(\d+)/ && print $1') | |
if [[ ! -z "$latency" ]]; then | |
if [ "$latency" -gt $LATENCY_THRESHOLD ]; then | |
echo "🟡 $latency" | |
else | |
echo "🟢 OK" | |
fi | |
else | |
echo "🔴 No Wifi" | |
osascript -e "display notification \"Network intermitency detected\" with title \"Internet check\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment