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,
  • 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)

wifiWatcher = nil

function ssidChanged()
    local wifiName = hs.wifi.currentNetwork()
    if wifiName then
        wifiMenu:setTitle("Wifi OFF")

wifiWatcher =
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 (2)

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!

mcrowder65 profile image
Matt Crowder

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