I am thinking of having a hammerspoon wifi watcher, which do a periodic check and will disable wifi if its not connected.
The following script does this,
function checkAndDisableWifi()
hs.timer.doAfter(45, function()
local current_network = hs.wifi.currentNetwork()
if current_network == nil then
hs.wifi.setPower(false)
hs.notify.new({title="Hammerspoon",informativeText="Disabling wifi due to inactivity"}):send()
end
end)
end
function wifi_timer_callback()
local wifi_state = hs.wifi.interfaceDetails().power
if wifi_state then
local current_network = hs.wifi.currentNetwork()
if current_network == nil then
hs.wifi.setPower(false)
hs.notify.new({title="Hammerspoon",informativeText="Disabling wifi due to inactivity"}):send()
end
else
hs.wifi.setPower(true)
checkAndDisableWifi()
end
end
local wifi_timer = hs.timer.doEvery((10*60), wifi_timer_callback)
wifi_timer:start()
Here I am facing an issue like what if the user is already connected via LAN. At this point of time I dont need to do enable this watcher ( so as to stop doing switching of wifi ON and OFF). So what I need is , Is there any API which can tell me whether the user is already connected via LAN or atleast connected to internet?
Am I clear?
hs.network.interfaceDetails(v4)
looks like a snippet from a larger config, because it's wrong in isolation. – Tennyson