Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created February 26, 2015 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jacobsalmela/9fe37501ca9f2144dfdf to your computer and use it in GitHub Desktop.
Save jacobsalmela/9fe37501ca9f2144dfdf to your computer and use it in GitHub Desktop.
Remove an SSID from the preferred networks list
#!/bin/bash
#----------VARIABLES---------
undesiredNetwork="SSID-To-Remove"
wifiOrAirport=$(/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Wi-Fi|AirPort)')
echo $wifiOrAirport
wirelessDevice=$(networksetup -listallhardwareports | awk "/$wifiOrAirport/,/Device/" | awk 'NR==2' | cut -d " " -f 2)
echo $wirelessDevice
#-----------SCRIPT-----------
# Remove the SSID from the list of preferred networks
networksetup -removepreferredwirelessnetwork "$wirelessDevice" "$undesiredNetwork"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment