I tried this script on my machine and was able to add a wifi network to the top of the list and remove an old one. See if it works for you.
#!/bin/sh newSSID="SSID_OF_NEW_WIRELESS_NETWORK" # Security type is OPEN for none, WPA for WPA, Personal, WPA2 for WPA2 Personal, WPA/WPA2 for WPA/WPA2 Personal, # WPAE for WPA Enterprise, WPA2E for WPA2 Enterprise, WPAE/WPA2E for WPA/WPA2 Enterprise, WEP for plain WEP, # and 8021XWEP for 802.1X WEP securityType="SECURITY_TYPE" newPassword="WIRELESS_NETWORK_PASSPHRASE" oldSSID="SSID_OF_OLD_WIRELESS_NETWORK" #Add Wifi network at top of list networksetup -addpreferredwirelessnetworkatindex en1 $newSSID 0 $securityType $newPassword #Remove old SSID networksetup -removepreferredwirelessnetwork en1 $oldSSID
@paulr4 -- I noticed that pcregrep is used in this script but is not a default binary to macOS. I cannot just swap with "grep" (it seems to remove ALL my SSIDs) ... do you have a suggestion using binaries that come shipped with macOS?
$ sudo bash Ntwk_WiFiPriority.sh Password: There are 10 entries in preferred network list. Ntwk_WiFiPriority.sh: line 52: /usr/local/bin/pcregrep: No such file or directory $ which pcregrep $ which grep /usr/bin/grep