Created
March 2, 2024 05:57
-
-
Save RealTong/6291ee30dc93d59af52e30610845cdf0 to your computer and use it in GitHub Desktop.
show network status in Raycast
This file contains 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 | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title SSID Name | |
# @raycast.mode inline | |
# @raycast.refreshTime 1m | |
# Optional parameters: | |
# @raycast.icon 🛜 | |
# @Documentation: | |
# @raycast.packageName Network | |
# @raycast.description Get current network ssid name. | |
# @raycast.author Alexandru Turcanu | |
# @raycast.authorURL https://github.com/Pondorasti | |
function get_wifi_ssid () { | |
service_info=$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport --getinfo) | |
ssid_line=$(echo "$service_info" | grep -v "BSSID" | grep "SSID") | |
ssid=$(echo "$ssid_line" | awk -F "(: )" '{print $2}') | |
echo "$ssid" | |
} | |
function get_internet_status () { | |
if ! ping -q -c 2 baidu.com &>/dev/null; then | |
echo " (No Internet)" | |
fi | |
} | |
current_device=$(route get default 2>/dev/null | grep "interface" | awk '{print $2}') | |
# Exit if there's no connection | |
if [ -z "$current_device" ]; then | |
echo "No connection" | |
exit 0; | |
fi | |
service_info=$(networksetup -listnetworkserviceorder | grep "$current_device") | |
service_name=$(echo "$service_info" | awk -F "(, )|(: )|[)]" '{print $2}') | |
wifi_ssid=$(get_wifi_ssid) | |
network_status="" | |
if grep -q "USB" <<< "$service_name"; then | |
network_status+="Ethernet" | |
network_status+=$(get_internet_status) | |
# Check if also connected to Wi-fi | |
if [ -n "$wifi_ssid" ]; then | |
network_status+=" | $wifi_ssid" | |
fi | |
elif grep -q "Wi-Fi" <<< "$service_name"; then | |
network_status+="$wifi_ssid" | |
network_status+=$(get_internet_status) | |
fi | |
private_ip=$(ipconfig getifaddr $current_device) | |
gateway=$(netstat -nr | grep default | awk '{print $2}') | |
echo "$network_status | IP: $private_ip | Gateway: $gateway" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment