hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

`hs.wifi` not showing current network in Sonoma 14.2.1

Open andreoliwa opened this issue 1 year ago • 2 comments

👋🏻 It seems that something is off with hs.wifi.currentNetwork() after I upgraded macOS to Sonoma.

I added this to init.lua for debugging:

local networks = hs.wifi.availableNetworks()
print('WiFi available:')
for i, network in ipairs(networks) do
    print(i, network)
end
local interfaces = hs.wifi.interfaces()
print('WiFi interfaces:')
for i, interface in ipairs(interfaces) do
    print(i, interface)
end
local currentNetwork = hs.wifi.currentNetwork()
if currentNetwork then
    print('WiFi network: ' .. currentNetwork)
else
    print('WiFi network: Not connected')
end

This is the output:

2024-01-23 11:29:55: -- Loading extension: wifi
2024-01-23 11:29:58: WiFi available:
2024-01-23 11:29:58: WiFi interfaces:
2024-01-23 11:29:58: 1	en0
2024-01-23 11:29:58: WiFi network: Not connected

This is a laptop administered by my company with an inventory tracking app running in the background. I have full admin/root/sudo permissions, though. I don't know if this is somehow related since Sonoma started asking for my authorisation in other places.

I don't know how to debug it further, any ideas?

andreoliwa avatar Jan 23 '24 10:01 andreoliwa

It looks like there was a change in permissions in Sonoma. Location Services has to be enabled and the app has to request access to be able to see the ssid property.

voldemortensen avatar Jan 27 '24 18:01 voldemortensen

The problem is hs.wifi.currentNetwork() always return nil in Sonoma.

And this solution worked for me. After granting Location Services permission to Hammerspoon, hs.wifi.currentNetwork() functions correctly now and does not just return nil.

firmmaple avatar Feb 14 '24 02:02 firmmaple

  • Thanks, the solution from https://github.com/Hammerspoon/hammerspoon/issues/3537#issuecomment-1743870568 works, indeed.

Closing this as a duplicate (I don't know why I didn't find the other issue before 🤔).

andreoliwa avatar Mar 11 '24 13:03 andreoliwa