If you find yourself wondering how to have the name of the network you're connected to on your menu bar, then follow these instructions.
We'll be using an application called hammerspoon, which allows your computer to run lua scripts in the background!
- Go to hammerspoon's github releases and install the latest one. You'll find something like this:
- Click the first choice,
Hammerspoon-0.9.73.zip
Drag the Hammerspoon application to your Applications
Once in applications, open Hammerspoon with spotlight (press command and space, and type in Hammerspoon, then press enter)
Once Hammerspoon has been opened for the first time, you should see a security prompt:
Click Open
Check
Launch Hammerspoon at login
Great, now we can add our init script!
Open your terminal and enter,
touch ~/.hammerspoon/init.lua
,Now open init.lua, (located at
~/.hammerspoon/init.lua
)Paste in the following code:
wifiMenu = hs.menubar.newWithPriority(2147483645)
wifiMenu:setTitle(hs.wifi.currentNetwork())
wifiWatcher = nil
function ssidChanged()
local wifiName = hs.wifi.currentNetwork()
if wifiName then
wifiMenu:setTitle(wifiName)
else
wifiMenu:setTitle("Wifi OFF")
end
end
wifiWatcher = hs.wifi.watcher.new(ssidChanged):start()
- Quit hammerspoon using
cmd+q
, (not just pressing the red x) - Reopen hammerspoon
And voila! We now have the name of our network on our menu bar!
Top comments (3)
I've found an issue that shows nothing if the computer was offline at startup. So I modified it like:
Thanks for sharing. It's very useful!
Thanks! Iโll update it when I get a chance
Hope someone can help me out. I am on SONOMA and SSID is not working anymore with the above code. Always shows "Wifi OFF", even when I am on WiFi.
Used this code:
wifiMenu = hs.menubar.newWithPriority(2147483645)
wifiMenu:setTitle(hs.wifi.currentNetwork())
wifiWatcher = nil
function ssidChanged()
local wifiName = hs.wifi.currentNetwork()
if wifiName then
wifiMenu:setTitle(wifiName)
else
wifiMenu:setTitle("Wifi OFF")
end
end
wifiWatcher = hs.wifi.watcher.new(ssidChanged):start()