Last active
December 28, 2023 22:30
-
-
Save ryanb8/6454a5c42af92f22e182537fde30682f to your computer and use it in GitHub Desktop.
xbar plugin - Print active internet interface
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
#!/usr/bin/env bash | |
# A simple plugin for xbar to print the interface you are conntected to the internet with. | |
# See: https://github.com/matryer/xbar and https://xbarapp.com/ | |
# Probably could be a plugin in xbar repo, TBD. | |
# Use case - sometimes my mac uses wifi when it shoudl use ethernet. | |
# Instructions: | |
# Name `ethernet_or_wifi.5m.sh` | |
# chmod +x it | |
# Thanks to: https://apple.stackexchange.com/questions/191879/how-to-find-the-currently-connected-network-service-from-the-command-line#comment635764_433612 | |
default_route=$(route get default) | |
if [[ "$default_route" == '' ]]; then | |
source="Unconnected" | |
else | |
networks=$(networksetup -listnetworkserviceorder) | |
interface=$(echo "$default_route" | awk '/interface/ {print $2}' ) | |
source=$(echo "$networks" | awk -v interface="$interface" "/$interface/{sub(/\([0-9]+\)\ /,\"\",a); print a} {a=\$0}") | |
fi | |
echo "$source" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my menu bar:
or
or