Using Terminal to order SSID preference in System Preferences
I'd like to find a way to add a specific SSID to the top of the preferred WiFi networks in System Preferences > Network > WiFi > Advanced. (10.9 Mavericks and beyond)
According to the man page, this should do it:
-addpreferredwirelessnetworkatindex hardwareport network index securitytype [password]
However, it doesn't appear the 'index' aspect actually sets one network name above the other. Is there a way to set this via terminal and/or run via bash?
A couple of things to consider:
Supposedly, specifying 0 for the index puts it at the front of the list.
You need at least admin privilege and may need root privilege. Have you tried it with:
sudo networksetup -addpreferredwirelessnetworkatindex ...
?If the wireless network is already a preferred network, you may need to remove it first before adding it again. That is, it may be ignoring the index if the network already has an index. Assuming your wireless port is en1, you can get the list of preferred networks with:
networksetup -listpreferredwirelessnetworks en1
. I admit that I'm just guessing here.If you have multiple wireless ports, it will of course make a difference which one you add this service to. You can list all your
hardwareport
s, wireless and otherwise, with:networksetup -listnetworkserviceorder