Git Product home page Git Product logo

wifi-location-changer's Introduction

Mac OSX Wi-Fi Location Changer

  • 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
  • Manage last OSX (up to 14.5) changes in airport and wdutil program

Configuration

Create a configuration file using the sample:

cp ./locationchanger.conf.sample ./locationchanger.conf

Add 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!

Add as many location + SSID lines as you like to the configuration file.

MacOS Notifications

The script triggers a MacOS Notification upon changing location. If you don't want this just delete the lines that start with osascript.

Installation

Automated Installation

Execute:

./install.sh

Manual Installation

Copy these files:

cp locationchanger /usr/local/bin
cp locationchanger.conf /usr/local/bin
cp LocationChanger.plist ~/Library/LaunchAgents/

Should you place the locationchanger script to another location, make sure you edit the path in LocationChanger.plist too.

Make locationchanger script executable:

chmod +x /usr/local/bin/locationchanger

Load LocationChanger.plist as a launchd daemon:

launchctl load ~/Library/LaunchAgents/LocationChanger.plist

Logfile

Logfile location can be adjusted in locationchanger, around line 12:

exec &>/usr/local/var/log/locationchanger.log

See log in action:

tail -f /usr/local/var/log/locationchanger.log

Run arbitrary script when location changes

By 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.

Testing

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

MacOS Ventura/Sonoma fallback to Automatic location issue

This repository already handles the case already if the SSID is not listed in the config file. In that case it should switch to the location Automatic, but it requires root access to do so. This is the default behaviour so you just need to do the following step.

Modify the sudoers file

  • Run sudo visudo
  • replace your_user_name with your username
    • you can type whoami to see you current username
# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
your_user_name ALL=(ALL) NOPASSWD: /usr/local/bin/locationchanger

Run the ./install.sh script again - and now your location network settings are set to Automatic if no mapping has been found!

wifi-location-changer's People

Contributors

abencz avatar ericlifeac avatar fudesign2008 avatar infn8 avatar jikamens avatar kaylukas avatar klizzy avatar lrangelaugusto avatar luozhihua avatar marcool04 avatar matteofilippetto avatar mihaisiia avatar mikedevita avatar mr-david avatar putchi avatar red54 avatar rimar avatar rocco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.