- Automatically changes the Mac OSX network location when a configured Wi-Fi (SSID) becomes connected
- Allows having different IP settings depending on the Wi-Fi SSID
- Offers hook to run external script when location changes
-
Install LocationChanger:
./install.sh
-
Configure SSID mappings:
./config-ui.sh
- Select option 1 to add SSID mappings
- Select option 5 to install if not already done
-
Set up sudoers (required for location switching):
sudo visudo
Add this line (replace
your_usernamewith your actual username):your_username ALL=(ALL) NOPASSWD: /usr/local/bin/locationchanger-helper -
Test the service by switching between different Wi-Fi networks
The easiest way to configure LocationChanger is using the interactive configuration tool:
./config-ui.shThis provides a user-friendly interface for all configuration tasks. See the Configuration UI section below for detailed instructions.
The script triggers a MacOS Notification upon changing location. If you don't want this just delete the lines that start with osascript.
The easiest way to install LocationChanger is through the configuration tool:
./config-ui.shThen select option 5 (Install LocationChanger). This will:
- Run the installation script
- Preserve any existing configurations
- Provide guidance for next steps
Execute:
./install.shCopy these files:
cp locationchanger /usr/local/bin
cp locationchanger-helper /usr/local/bin
cp locationchanger.conf /usr/local/bin
cp LocationChanger.plist ~/Library/LaunchAgents/Make scripts executable:
chmod +x /usr/local/bin/locationchanger
chmod +x /usr/local/bin/locationchanger-helper
sudo chown root /usr/local/bin/locationchanger-helper
sudo chmod 500 /usr/local/bin/locationchanger-helperLoad LocationChanger.plist as a launchd daemon:
launchctl load ~/Library/LaunchAgents/LocationChanger.plistNote: Should you place the locationchanger script to another location, make sure you edit the path in LocationChanger.plist too.
Logfile location can be adjusted in locationchanger, around line 12:
exec &>/usr/local/var/log/locationchanger.logSee log in action:
tail -f /usr/local/var/log/locationchanger.logBy convention, placing an executable script in this directory with name:
locationchanger.callout.sh
and then running the installer, will cause the locationchanger service to run that script each time location changes.
For ease in testing, configure two locations within the current environment, e.g., "home" and "guest", each associated with a different SSID, such as the main SSID and guest SSID on your router. Then using the Wi-Fi menu, toggle between those SSIDs. You can see any success or error messages that are written to the log with a command like:
tail /usr/local/var/log/locationchanger.log./config-ui.shSelect option 6 (Uninstall LocationChanger) for a complete removal of all files and configurations.
# Stop the service
launchctl unload ~/Library/LaunchAgents/LocationChanger.plist
# Remove files
sudo rm -f /usr/local/bin/locationchanger
sudo rm -f /usr/local/bin/locationchanger-helper
sudo rm -f /usr/local/bin/locationchanger.conf
sudo rm -f /usr/local/bin/locationchanger.conf.backup
sudo rm -f /usr/local/bin/locationchanger.callout.sh
rm -f ~/Library/LaunchAgents/LocationChanger.plist
sudo rm -f /usr/local/var/log/locationchanger.log
# Remove sudoers entry manually
sudo visudo
# Remove the line: your_username ALL=(ALL) NOPASSWD: /usr/local/bin/locationchanger-helperThis version includes support for macOS Sequoia 15.0+ by using the Shortcuts app to detect Wi-Fi SSIDs when traditional methods fail. The script automatically falls back to legacy methods if Shortcuts is not available.
Note: macOS 15.0+ has enhanced privacy protections that may prevent automatic SSID detection. If you see Privacy Protected or <redacted> in the configuration tool, you can still manually configure SSID mappings. For automatic detection, create a Shortcuts app shortcut named "Current Wi-Fi".
Open the Shortcuts app → click + to add a new shortcut → in the right pane select Device → drag Get Network Details to the left pane → then go to the Scripting section, find Stop and Output, and drag it below → run it with the Play button (you should see your current Wi-Fi name) → name the shortcut Current WiFi (at the top of the window) → close the window and the app.
Starting with macOS Sequoia 15.5+, changing network locations requires admin privileges. This project uses a secure helper script approach to minimize security risks.
Security Benefits:
- Only the specific helper script can be executed without password
- Helper script is owned by root with restricted permissions (500)
- Helper script only allows network location switching, preventing privilege escalation
- Input validation prevents injection attacks
If no SSID mapping is found in the configuration file, the script automatically switches to the "Automatic" location. This requires the same sudoers configuration as above.
A comprehensive command-line configuration tool is available for easy management of LocationChanger.
./config-ui.shThis interactive tool provides a complete management interface with the following features:
- Add SSID mapping - Create new Wi-Fi to location mappings
- Remove SSID mapping - Delete existing mappings
- Refresh current SSID - Update current Wi-Fi status
- View configuration file - Display current configuration
- Install LocationChanger - Run the installation script and preserve existing mappings
- Uninstall LocationChanger - Complete removal of all files and configurations
- Exit - Quit the configuration tool
- Visual Interface: Clean, colorized terminal interface with clear status displays
- Current Status: Shows current Wi-Fi SSID and mapping count
- Smart Installation: Preserves existing mappings during installation
- Complete Uninstall: Removes all files, configurations, and services
- Error Handling: Comprehensive error checking and user feedback
- Permission Management: Handles sudo requirements automatically
# Start the configuration tool
./config-ui.sh
# The tool will show:
# - Current Wi-Fi status
# - Existing mappings
# - Interactive menu for all operations- Run
./config-ui.sh - Select option 5 (Install LocationChanger)
- The tool will:
- Check for existing mappings
- Run the installation script
- Restore your configurations
- Provide next steps for sudoers setup
- Run
./config-ui.sh - Select option 6 (Uninstall LocationChanger)
- Confirm the removal
- The tool will:
- Stop the service
- Remove all files
- Clean up configurations
- Provide guidance for sudoers cleanup
If you prefer manual configuration, create a configuration file using the sample:
cp ./locationchanger.conf.sample ./locationchanger.confAdd to this new file (./locationchanger.conf) a single line for each pair of location and SSID that you want this service to recognize and set when the SSID connects. That is, for each location, add one line with both a location name and a Wi-Fi SSID, separated by a space, taking care to use exact capitalization, and using quotations as necessary.
For example, if your location is "home", and the Wi-Fi SSID to trigger that location is "myWifiName", then a line in the configuration file would look like:
home myWifiName
If your SSID is instead a name like Wu Tang LAN, with spaces, then use quotes around the SSID like:
home "Wu Tang LAN"
Note: Ensure you use the exact location names as they appear under "Location" in OSX's System Preferences -> Network, and for SSIDs in your Wi-Fi menu. Capitalization must match! Spaces must match within a quoted name!
Manual Setup (Required for location switching):
- Run
./install.shto install the helper script - Add the following line to your sudoers file:
Add this line (replace
sudo visudo
your_usernamewith your actual username):To find your username:your_username ALL=(ALL) NOPASSWD: /usr/local/bin/locationchanger-helperwhoami