Skip to content

Instantly share code, notes, and snippets.

@rvdm
Created July 31, 2017 08:16
Show Gist options
  • Save rvdm/9e21e76ced4b0b4af5744bdf0d13dfd2 to your computer and use it in GitHub Desktop.
Save rvdm/9e21e76ced4b0b4af5744bdf0d13dfd2 to your computer and use it in GitHub Desktop.
local wifiWatcher = nil
local homeSSID = "trustedhomewifi"
local lastSSID = hs.wifi.currentNetwork()
function ssidChangedCallback()
newSSID = hs.wifi.currentNetwork()
networkconfig = hs.network.configuration.open()
if newSSID == homeSSID and lastSSID ~= homeSSID then
-- joined home wifi
networkconfig:setLocation("Automatic")
hs.alert.show("Welcome home!")
elseif newSSID ~= homeSSID and lastSSID == homeSSID then
-- departed home wifi
networkconfig:setLocation("sshvpn")
hs.alert.show("Danger, Will Robinson!")
end
lastSSID = newSSID
end
wifiWatcher = hs.wifi.watcher.new(ssidChangedCallback)
wifiWatcher:start()
@rvdm
Copy link
Author

rvdm commented Jul 31, 2017

  • Have a network location set up in OSX called 'sshvpn' (or change the script) that routes everything trough your VPN
  • Set homeSSID to trusted SSID
  • Hammerspoon switches the location to 'sshvpn' when not connected to home network

.. obviously easily adjusted to support multiple SSIDs etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment