NetworkLocationManager.spoon
Hammerspoon Spoon — auto-switch macOS Network Locations by WiFi SSID. Dual detection (SSID + gateway MAC), settling cooldown, JSON or Lua config.
A Hammerspoon plugin for Mac that automatically switches macOS Network Locations based on which WiFi network you are connected to.
NetworkLocationManager.spoon is a plugin, called a Spoon, for a Mac automation tool named Hammerspoon. It solves a specific annoyance for people who need a fixed local IP address on their home WiFi network, for example to set up port forwarding or run a self hosted service, but want their Mac to fall back to normal automatic addressing everywhere else. macOS already has a feature called Network Locations for switching between these setups, but switching manually every time you leave or return home is easy to forget.
The README explains that every common command line way of reading the current WiFi network name on recent macOS is broken or blocked in some way, so this Spoon instead uses Hammerspoon's own WiFi module, which talks to the operating system's WiFi framework directly and only needs a one time Location Services permission grant. When that permission is not available, it falls back to identifying the network by your router's hardware address instead, though switching takes a few seconds longer that way.
Setup involves creating the Network Locations you want inside macOS system settings, for example a Home location with a static IP, and then telling the Spoon which WiFi network names map to which location, either directly in your Hammerspoon configuration file or through a separate JSON file. The Spoon watches for WiFi changes, network reachability changes, and also checks on a timer, then switches locations automatically when it detects a match. A short cooldown period after each switch stops it from repeatedly re-triggering itself.
The README lists example use cases such as peer to peer file sharing apps, home media servers, VPN configuration per location, and switching DNS providers depending on where you are. It requires macOS 14 or newer and Hammerspoon installed, and is released under the MIT license.
Where it fits
- Automatically get a static local IP at home for port forwarding while using DHCP everywhere else.
- Switch VPN or DNS configuration automatically based on which WiFi network you join.
- Keep self-hosted services like Plex or a game server reachable at a fixed home IP.