matryer / xbar-plugins

Plugin repository for xbar (the BitBar reboot)
https://xbarapp.com
2.46k stars 1.04k forks source link

dnscrypt-proxy-switcher doesn't work if user has manually changed interface name #2060

Open shwayder opened 2 months ago

shwayder commented 2 months ago

In recent MacOS, the user is able to manually change the name of the network interface in the "Network" pane of the System Settings. If the user does this, then the dnscrypt-proxy-switcher script fails for that interface as the script is trying to use the hardware interface name, not the network interface name and then the 'networksetup -setdnsservers' call fails.

Fortunately, there is a simple fix. Line 63 of the script needs to be changed. Old line 63: currentservice="$sname" New line 63: currentservice=$(networksetup -listnetworkserviceorder | grep -B1 "Device: $sdev" | head -n1 | sed 's/^([0-9]*) //')

This new line takes the active network interface (e.g., 'en3') and then uses the networksetup tool to find the interface name associated with that network interface.

In addition line 58 (sname=$(echo "$line" | awk -F "(, )|(: )|[)]" '{print $2}')) can now be commented out as it is unnecessary.