Skip to content

Instantly share code, notes, and snippets.

@gjazali
Last active April 21, 2025 14:45
Show Gist options
  • Save gjazali/8299b97f9811d014d7fa7c12d3414771 to your computer and use it in GitHub Desktop.
Save gjazali/8299b97f9811d014d7fa7c12d3414771 to your computer and use it in GitHub Desktop.
Configure SwiftBar and `launchd` to show a network interface indicator on the macOS menu bar.

SwiftBar Network Interface Indicator

This gist contains an instruction to configure SwiftBar and launchd to show a network interface indicator on the macOS menu bar. This allows you to tell when an ethernet connection is used over a wireless connection (a feature that is not provided by macOS).

First, put the files attached below in the following locations:

  • network-interface.sh in your SwiftBar plugin folder (e.g., ~/.swiftbar_plugins/network-interface.sh (change the permission octal to 755).
  • org.jazali.network-listener.plist in /Library/LaunchAgents/org.jazali.network-listener.plist (change the permisson octal to 600).
  • refresh_swiftbar_network_interface.sh in the directory where you put your scripts; e.g., ~/scripts/refresh_swiftbar_network_interface.sh (change the permission octal to 755).

Note that you can change the identifier org.jazali into any unique identifier you desire, such as com.user. Also, the icons in network-interface.sh are SF Symbols icons, which should be fully supported on all modern Apple devices.

After that, use launchd's launchctl bootstrap to load the listener:

sudo launchctl bootstrap gui/$(id -u) /Library/LaunchAgents/org.jazali.network-listener.plist

You can also use launchctl bootout to unload the listener if you ever need to:

sudo launchctl bootout gui/$(id -u) /Library/LaunchAgents/org.jazali.network-listener.plist
#!/bin/bash
# <swiftbar.title>Network Interface Name</swiftbar.title>
# <swiftbar.version>v1.0</swiftbar.version>
# <swiftbar.author>G.A. Jazali</swiftbar.author>
# <swiftbar.desc>Shows an indicator that shows whether or not LAN is connected.</swiftbar.desc>
WIRED_ICON="􀩲"
WIRELESS_ICON="􀖀"
NO_INTERNET_ICON="􁣡"
DEFAULT_INTERFACE=$(route get default 2>/dev/null | awk '/interface: / { print $2 }')
if [[ "$DEFAULT_INTERFACE" == en0 ]]; then
echo "$WIRELESS_ICON $DEFAULT_INTERFACE"
elif [[ "$DEFAULT_INTERFACE" == "" ]]; then
echo "$NO_INTERNET_ICON Offline"
else
echo "$WIRED_ICON $DEFAULT_INTERFACE"
fi
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.jazali.network-listener</string>
<key>OnDemand</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/Users/jazali/scripts/refresh_swiftbar_network_interface.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
</dict>
</plist>
#!/bin/bash
open -g swiftbar://refreshplugin\?name=network-interface
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment