Skip to content

Instantly share code, notes, and snippets.

@elvisizer
Last active January 11, 2018 01:26
Show Gist options
  • Save elvisizer/9d22d7d7e82c672841b284617ab30325 to your computer and use it in GitHub Desktop.
Save elvisizer/9d22d7d7e82c672841b284617ab30325 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "detecting network hardware"
networksetup -detectnewhardware
sleep 1
echo "setting network service order"
while read networkService; do
if [[ ${networkService} == "Thunderbolt Bridge" ]]; then
deprioritizedServices+=( "${networkService}" )
elif [[ ${networkService} =~ .*Ethernet.* ]] || [[ ${networkService} =~ .*Thunderbolt.* ]]; then
prioritizedServices+=( "${networkService}" )
elif [[ ${networkService} =~ .*Bluetooth.* ]] || [[ ${networkService} =~ .*FireWire.* ]]; then
deprioritizedServices+=( "${networkService}" )
else
otherServices+=( "${networkService}" )
fi
done < <( networksetup -listnetworkserviceorder | awk '/^\([0-9]/{$1 ="";gsub("^ ","");print}' )
networksetup -ordernetworkservices "${prioritizedServices[@]}" "${otherServices[@]}" "${deprioritizedServices[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment