Created
December 6, 2022 02:50
-
-
Save yukixz/42706cd892930329088e6bee6cae18e9 to your computer and use it in GitHub Desktop.
Hammerspoon script: Set Network Location by WiFi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---- 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