WiFiLocControl allows you to change your macOS network location automatically based on the Wi-Fi network (SSID) you are connected to. It is particularly useful for users who use Wi-Fi at work and at home, but the network settings (for example, custom DNS configurations) you use at work don't allow your Mac to automatically connect to the same type of network at home.
- Automatically changes network locations based on current Wi-Fi name.
- Supports alias configurations for multiple Wi-Fi names.
- Executes location-specific scripts.
- Clone the repository to your local machine.
git clone https://github.com/vborodulin/wifi-loc-control.git
cd wifi-loc-control- Run the bootstrap script to set up the environment.
chmod +x bootstrap.sh
./bootstrap.shIt will ask you for a root password to install WiFiLocControl to the /usr/local/bin directory and set up required permissions for macOS 26+.
- To check logs for activity:
tail -f ~/Library/Logs/WiFiLocControl.log- To uninstall, run:
sudo rm /usr/local/bin/wifi-loc-control.sh
rm -rf ~/.wifi-loc-control
rm ~/Library/LaunchAgents/WiFiLocControl.plist
sudo rm /etc/sudoers.d/wifi-loc-control
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/WiFiLocControl.plistTo set up specific preferences for your Wi-Fi networks, keep it easy: just name your network locations after
your Wi-Fi names. For example, if you want special settings for My_Home_Wi-Fi_5GHz, make a
location called My_Home_Wi-Fi_5GHz. When you connect to that Wi-Fi, your location will switch
automatically. If you connect to a Wi-Fi without a special name, it defaults to Automatic.
To share one network location between different wireless networks (for example, if you have a router broadcasting on multiple bands, or want to group several SSIDs under one profile), create a configuration file ~/.wifi-loc-control/alias.conf (plain text file with simple key-value pairs):
mkdir -p ~/.wifi-loc-control
nano ~/.wifi-loc-control/alias.confExample contents:
My_Home_Wi-Fi_5GHz=Home
My_Home_Wi-Fi_2.4GHz=Home
My_Work_Wi-Fi_5GHz=Work
My_Home_Wi-Fi_2.4GHz=Work
Where the keys are the wireless network names and the values are the desired location names.
You can also use the private and fixed Wi-Fi address that macOS can generate for each Wi-Fi network:
# My_Home_Wi-Fi_5GHz
d2:1a:f8:5d:bb:ac=Home
# My_Home_Wi-Fi_2.4GHz
cf:0a:4e:8a:4b:fe=Home
Sometimes you want to execute a script every time you connect to a specific Wi-Fi network. For example enable stealth or enable firewall mode. Follow these steps:
- Place your scripts in
~/.wifi-loc-control/. - Name the scripts after the Wi-Fi network name, ensuring consistency with the corresponding network locations.
Example script (~/.wifi-loc-control/My_Home_Wi-Fi_5GHz):
#!/usr/bin/env bash
# Collect all output from this script to ~/Library/Logs/WiFiLocControl.log
exec 2>&1
# Enable stealth mode which makes your computer less visible to potential attackers
/usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onTo reset changes made by specific location scripts, create corresponding reset script.
Example reset script (~/.wifi-loc-control/Automatic):
#!/usr/bin/env bash
exec 2>&1
# Disable stealth mode which makes your computer less visible to potential attackers
/usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate offMake scripts executable
chmod +x ~/.wifi-loc-control/My_Home_Wi-Fi_5GHz
chmod +x ~/.wifi-loc-control/AutomaticRich logs available at ~/Library/Logs/WiFiLocControl.log.
tail -f ~/Library/Logs/WiFiLocControl.logLogs examples:
[2023-11-26 13:44:49] current wifi_name 'My_Home_Wi-Fi_5GHz'
[2023-11-26 13:44:49] network locations: Automatic Home
[2023-11-26 13:44:49] current network location 'Automatic'
[2023-11-26 13:44:49] reading alias config '/Users/vborodulin/.wifi-loc-control/alias.conf'
[2023-11-26 13:44:49] for wifi name 'My_Home_Wi-Fi_5GHz' found alias 'Home'
[2023-11-26 13:44:49] location switched to 'Home'
[2023-11-26 13:44:49] finding script for location 'Home'
[2023-11-26 13:44:49] running script '/Users/vborodulin/.wifi-loc-control/Home'
Contributions are welcome! If you have suggestions, improvements, or encounter issues, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.