Skip to content

Instantly share code, notes, and snippets.

@yukixz
Created December 6, 2022 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukixz/42706cd892930329088e6bee6cae18e9 to your computer and use it in GitHub Desktop.
Save yukixz/42706cd892930329088e6bee6cae18e9 to your computer and use it in GitHub Desktop.
Hammerspoon script: Set Network Location by WiFi
---- Set Network Location to profile named by SSID or Automatic on WiFi change ----
network_configuration = hs.network.configuration.open()
watcher_wifi = hs.wifi.watcher.new(function()
local ssid = hs.wifi.currentNetwork()
if (ssid == nil) then
return
end
log.i('WiFi Changed to '..ssid)
local new_loc = 'Automatic'
for uid, name in pairs(network_configuration:locations()) do
if (name == ssid) then
new_loc = name
end
end
network_configuration:setLocation(new_loc)
end)
watcher_wifi:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment