Connect to Wi-Fi via CLI / Script

If you ever got an error like „Error: -3924 Invalid PMK Failed to join network“ on OS X try to enclose the Wi-Fi Password in single quotes.

I use this script in a DeployStudio workflow for connecting to a default Wi-Fi Network without revealing the password to the user.


# Activate Wi-Fi on en1 and join SSID with password
	networksetup -setairportpower en1 on
	networksetup -setairportnetwork en1 SSID 'Password'
exit 0