Skip to content

Instantly share code, notes, and snippets.

@pbredenberg
Created September 11, 2019 15:27
Show Gist options
  • Save pbredenberg/1d5f7c94db783c5973e23ffd92b60494 to your computer and use it in GitHub Desktop.
Save pbredenberg/1d5f7c94db783c5973e23ffd92b60494 to your computer and use it in GitHub Desktop.
macOS WiFi connection script
#!/bin/bash
WIFI_INTERFACE=$(networksetup -listallhardwareports | awk '/Wi-Fi/{getline; print $2}')
NETWORK_SSID=YourNetworkSSID
# You can set $NETWORK_PASSWORD in your profile if you don't want to be prompted for it every time.
PASSWORD=$NETWORK_PASSWORD
if [ -z ${PASSWORD+x} ]; then
echo "Give me the password for $NETWORK_SSID immediately!"
read PASSWORD
fi
echo "Ok, fine I'll connect you to $NETWORK_SSID if I can."
networksetup -setairportnetwork $WIFI_INTERFACE $NETWORK_SSID $PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment