DEV Community

Matt Crowder
Matt Crowder

Posted on

Configuring your mac to display the wifi name on the menu bar

a picture of a mac menu bar with network name attached

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!

picture of the hammerspoon releases on github

  • Click the first choice, Hammerspoon-0.9.73.zip
  • Once downloaded, unarchive the zip to your Downloads
    a picture of mac finder showing the downloads of hammerspoon

  • 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:
    image of accepting hammerspoon 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()
Enter fullscreen mode Exit fullscreen mode
  • 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)

Collapse
 
shotasenga profile image
Shota Senga

I've found an issue that shows nothing if the computer was offline at startup. So I modified it like:

wifiNameApp:setTitle(hs.wifi.currentNetwork() or "Offline")   

Thanks for sharing. It's very useful!

Collapse
 
mcrowder65 profile image
Matt Crowder

Thanks! I’ll update it when I get a chance

Collapse
 
jeroen_sdh profile image
Jeroen S.

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()