Displaying Your Wireless Network in the Touch Bar on a Macbook

If you have a Macbook laptop, you’re probably familiar with the touch bar. It’s a neat little LED display above the top row of your keyboard that Mac OS/X uses to display context-sensitive widgets. However, you don’t just have to accept the widgets that Apple provides–you can in fact customize the touchbar however you like.

“But why would I want to do this?”, I hear you ask. Well, maybe you need to have a custom status of some kind displayed on your menu bar. For me, it was… wireless networks.

MTMR is my new favorite utility.

That sounds confusing, but hear me out. Sometimes when I am traveling, I get kicked off of whatever wireless network I’m on. I wanted a way to easily determine what network I was on, without having to keep clicking on the wireless icon in my menu bar. I found that the touch bar was a convenient way to do that, and in this post, I will show you how I did it.

First, download an app called MTMR. MTMR stands for “My Touchbar. My rules.” Installation instructions are on that page, but most users will want the dmg file.

Once that’s installed, you can edit the file $HOME/Library/Application Support/MTMR/items.json to change what appears in the menu bar. The contents of the file are JSON, and you can edit this in whichever editor you like. Furthermore, once you save changes, they take effect immediately–no restarts of the MTMR app are necessary!

The next thing you’ll want to do is paste in this bit of JSON:

  {
    "type": "shellScriptTitledButton",
    "source": {
      "inline": "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I  | awk -F' SSID: '  '/ SSID: / {if ($2) print \"SSID: \" $2; else print \"NO SSID\"}'"
    },
    "action": "appleScript",
    "actionAppleScript": {
      "inline": "tell application \"System Preferences\"\ractivate\rreveal pane \"Network\"\rend tell"
    },
    "refreshInterval": 1,

    "width": 200,
    "align": "left"
  },

Note the comma at the end! You’ll want to leave that in if you’re putting more things in that file. That said, let’s walk through the more interesting parts of the JSON, starting with the”inline” section:

"type": "shellScriptTitledButton",
"source": {
  "inline": "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I  | awk -F' SSID: '  '/ SSID: / {if ($2) print \"SSID: \" $2; else print \"NO SSID\"}'"
},

What this does is it tells the MTMR app to run a command called airport, which prints out info on the wireless network you are connected to. That text is then piped into a utility called awk, which grabs the line with the SSID, strips out the “SSID:” text, and prints out just the name of the network you are connected to. If you are not on any wireless network, it prints “NO SSID” instead.

The other important part of that config that I want to talk about is what happens when you press on that button on the touchbar:

"action": "appleScript",
"actionAppleScript": {
   "inline": "tell application \"System Preferences\"\ractivate\rreveal pane \"Network\"\rend tell"
},

What this section does is that it tells MTMR that when the button on the touch bar is pressed, to run some AppleScript. AppleScript is a language to well… script actions in Mac OS/X. In this case, the Apple Script will open the Network pane in System Preferences whenever the button is clicked on.

Putting this all together, you’ll now have a status bar which shows which wireless network you’re on, and if you happen to drop off the network, a simple glance at the touch bar will confirm it, and then all you need to do is click on the touch bar to bring up your network preferences so you can rejoin the wireless network.

Here are some real life action shots:

This ended up being one of those “quality of life” tweaks that I didn’t know I needed for my setup until I made that change, and it has made things a lot more pleasant for me.

Enjoy!

Mirror on Medium.