Category filter
Script to configure Wi-Fi on Mac
On macOS devices, adding a new Wi-Fi network profile can be done by accessing the Wi-Fi option in the Network preferences. Configuring a single device may seem effortless; however, setting up Wi-Fi on multiple devices can be a tedious process. Additionally, when dealing with remotely managed devices, there needs to be a hassle-free way to configure the Wi-Fi network over the air. This can be especially useful when the passwords or other settings of a corporate network change over time and need to be reflected on the devices. Here’s an easy method to configure Wi-Fi networks on macOS devices using scripts. The script, which can be executed using the ‘Execute Custom Script’ action, allows the seamless setup of Wi-Fi networks on Mac devices remotely.
Scripting language – Bash
File extension – .sh
Configure Wi-Fi network
Running this script will automatically connect the device to the configured Wi-Fi network. The user will still be able to connect to other Wi-Fi networks or disable Wi-Fi from the device end. Unlike a Wi-Fi policy, which, when disassociated from the device, disconnects and forgets the configured Wi-Fi, the network configured using this script cannot be remotely disconnected or forgotten.
1 |
sudo networksetup –setairportnetwork <Wi-Fi interface name> <network SSID> <password> |
For example:
networksetup –setairportnetwork en0 ‘Company Wi-Fi' ‘Network@216’
networksetup
is a command-line tool used to configure a client’s network settings. It includes a variety of support commands to configure various network connections and related settings.- The
setairportnetwork
command is used to configure the Wi-Fi network of the macOS devices. - The
<Wi-Fi interface name>
field value is usually en0. This value can be found out by runningnetworksetup –listallhardwareports
command in the Mac terminal. Search for the device name under Hardware Port: Wi-Fi. - Replace
<network SSID>
with the required Wi-Fi network name. - Fill the
<password>
field if the Wi-Fi network is password secured.
What happens at the device end?
Once the script gets successfully executed, the configured Wi-Fi network will be listed under the Known Networks section in the System Settings/Preferences > Network.