For years, I’ve had a macOS bug that occurred randomly and that I could only fix by rebooting or logging out. The Internet is full of similar problems, but I never found a solution to mine, and my pleas for help on Twitter went unanswered. Now, I have found a workaround myself.

I always had a vague sense that web applications somehow trigger it, but I couldn’t ever nail it down, and even quitting all applications didn’t fix it. At least not always. It also occurred unpredictably: sometimes once per month, sometimes multiple times per day. I still don’t know what causes it, but I know how to fix it – until it appears the next time.

The Bug

When switching applications across desktops (for example, using ⌘⇥ or clicking an application icon), the window of the new application is taken away its focus after a few milliseconds. You can see how it very briefly has focus and then doesn’t.

You must click the window or application icon to activate it again because no window has focus at that moment. Pressing ⌘` (or whatever cycles through your windows – it’s the key over the tab key, left of the 1 key) can’t be used to switch focus to any window. It’s stuck in some weird limbo state where the correct application is active but no window is.

I usually run into this when switching between Safari and my terminal, and it’s maddening.

The Solution

Tear out any tab from Safari to make it a window. In other words: click a tab and drag it down.

Yes, I’m not kidding. Yes, it works 100% of the time – I’ve waited a few months and occurrences until I wrote this. It’s the only thing you have to do.

You can re-attach the tab to the original window afterwards; it will keep working.

Coda

This bug went away for good after I switched from Safari to the excellent Helium (yes, another Chromium-based browser).

So my suspicion seems to be confirmed: Safari’s deep OS integration is the cause of the bug.