A menu bar that survives macOS updates

I replaced the macOS menu bar with SketchyBar a while ago. It is the strip in the image above, and it shows what I want to see and nothing else.

It is also the part of my setup most likely to break when the operating system updates. This is what I have learned keeping it alive.

What the bar shows

On the left:

  • the workspace I am on
  • the app in focus, with its shortcut
  • the window layout in use

On the right:

  • CPU, memory and uptime for my Linux box
  • the same three numbers for the Mac
  • microphone, headphones, battery, network and the clock

Each group is a pill, and every colour comes from the same scheme as the rest of my desktop.

Why a custom bar breaks

A custom bar is not part of the system. It is an ordinary window, drawn at the top of the screen, sitting where the real menu bar would be.

macOS decides which windows sit in front of which by giving each a level. For the bar to work, it has to sit at the right level: above my apps, and not behind anything the system puts up there.

That arrangement is not a public contract. Apple can change how the top of the screen is layered in any release, and has.

The update that broke it

A recent macOS release added a new, always-present system window across the top of the screen. It is invisible, full width, and about as tall as the menu bar.

With the menu bar set to hide automatically, a click in that strip now went to the system. The native menu bar slid down, and my bar never received the click.

The bar still looked perfect. It simply stopped responding to the mouse, which is a confusing way for something to fail.

Finding the cause

What settled it was listing every window on screen, front to back, with its level. The new system window was at the same level as my bar, and in front of it.

Telling the bar to be topmost did not help. The two were still at the same level, and the system recreated its window in front after every app switch.

The fix: build it from source

The bar’s maintainers had an open issue for this, and someone had posted a patch. The patch lifts the bar one level higher while the menu bar is hidden, which puts it back in front.

Waiting for a release would have left the bar broken for weeks, so I stopped installing it from a package. A short script now runs as part of my normal update:

  1. Fetch the latest release of the bar’s source.
  2. Apply every patch in a folder in my dotfiles.
  3. Build it and install the result.

The script also tells me when to stop. If a new release already contains a patch, it says so and I delete the patch. If a patch no longer applies, it leaves the working build alone and tells me.

When the folder is empty, I go back to the package and retire the script.

Detect, do not assume

The layering bug taught me a wider lesson: this kind of software fails without telling you.

Widgets subscribe to events, and a subscription can silently never fire. One of mine did exactly that. A handler attached to an item inside a popup was never called, and the only evidence was a line in a log I was not reading.

Another widget combined two features that turn out not to work together. Its update script was dropped without an error, so the widget drew once and then never changed.

In both cases the bar looked fine.

The watchdog

So there is a watchdog. Every so often it asks the bar a simple question and waits up to five seconds for an answer.

sketchybar --query bar &>/dev/null &
QUERY_PID=$!

for i in {1..50}; do
  if ! kill -0 $QUERY_PID 2>/dev/null; then
    wait $QUERY_PID
    exit 0
  fi
  sleep 0.1
done

If the answer comes back, all is well. If it does not, the bar has hung, and the watchdog restarts it and writes down when.

A process that is running is not the same as a process that is working. The watchdog checks the second thing.

What I would tell someone starting

  • Expect breakage on every major release. Read the bar’s issue tracker before you update the system.
  • Keep patches as files, and let a script apply them. A hand-patched build is one you will forget how to make.
  • Check that it responds, not only that it is running.
  • Treat silence as a symptom. If a widget has not changed in a while, find out why.
Current theme

robot-reading-5k

Copied automatically from my desktop colorscheme, once a week. Dark mode uses these values as they are; light mode keeps each hue and flips the lightness.

RoleSchemeOn this page now
BackgroundPage background#0e0f17
SurfaceTiles and cards#181921
LineBorders and dividers#2a2c3d
TextBody text#cebead
AccentPrimary button and logo mark#e6d0ba
How this works