Quickly clean up your Wifi connections in OSX

Introduction

Today I realized that I had connected to a couple of hundred wifi networks over the last couple of years. This had clogged up my network preferences, and I no longer had a good overview of my favorite network locations.

Featured image

To clean this up, I did not feel like clicking through each and every one of these, so I found this (http://www.techrepublic.com/article/pro-tip-manage-wi-fi-with-terminal-commands-on-os-x/) which helped me with the CLI. Now I could:

  • List all networks to a file
  • Edit this file and remove my favorite networks from this file
  • Use this file to remove the unwanted networks
#--- count networks
malu@kmg-mcp001.local:/Users/malu $networksetup -listpreferredwirelessnetworks en0 | sort -f | sed -e 's/^[[:space:]]*//g' | grep -v "Preferred networks"  | wc -l
197

#--- list networks into a file
networksetup -listpreferredwirelessnetworks en0 | sort -f | sed -e 's/^[[:space:]]*//g' | grep -v "Preferred networks" > wifinetworks.txt

#--- edit the wifinetworks and remove your favorites, the ones to keep
vi wifinetworks.txt

#--- the next command will create a script to remove the networks in wifinetworks.txt, so use it with care
cat wifinetworks.txt | xargs -L1 -IX echo sudo networksetup -removepreferredwirelessnetwork en0 "X" > removewifi.sh

#--- check the removewifi.sh script and remove any favorites, then execute it
bash removewifi.sh

#--- count networks
malu@kmg-mcp001.local:/Users/malu $networksetup -listpreferredwirelessnetworks en0 | wc -l
   19