Monday, July 24, 2023
Fix for window focus issue on macOS Sonoma
Ever since installing a recent beta of macOS (Sonoma), windows have been losing focus. This was most evident in things like File->Open dialogs in, say, BBEdit, because the “Open” button could not be selected by hitting return. BBEdit would appear to be frontmost, but it was as if something invisible was getting in the way. It was driving me nuts, so after waiting too long I set out to solve it. A quick search led me to this thread on MacRumors
I found a Python script that would show me which application became frontmost every second.
/usr/bin/python3 -m venv ~/python-env
cd ~/python-env
# in bash
source bin/activate
# or, in fish shell
set VIRTUAL_ENV "/Users/jbaty/python-env
pip3 install pyobjc
Here’s the script (copied from the above thread)
#!./bin/python3
# Prints current window focus.
# See: https://apple.stackexchange.com/q/123730
from AppKit import NSWorkspace
import time
workspace = NSWorkspace.sharedWorkspace()
active_app = workspace.activeApplication()['NSApplicationName']
print('Active focus: ' + active_app)
while True:
time.sleep(1)
prev_app = active_app
active_app = workspace.activeApplication()['NSApplicationName']
if prev_app != active_app:
print('Focus changed to: ' + active_app)
Here’s what the output looked like after a few minutes of testing:
jbaty@MBP ~/python-env> python3 get_active_focus.py
Active focus: kitty
Focus changed to: BBEdit
Focus changed to: Hookmark Finder Extension
Focus changed to: BBEdit
Focus changed to: ForkLift
Focus changed to: Finder
Focus changed to: BBEdit
Focus changed to: Adobe Content Synchronizer Finder Extension
Focus changed to: BBEdit
Focus changed to: Wiki.app
Focus changed to: Adobe Content Synchronizer Finder Extension
Focus changed to: Arc
Focus changed to: System Settings
Focus changed to: BBEdit
Focus changed to: HoudahSpot Finder Extension
Focus changed to: BBEdit
It was readily apparent that Finder Extensions were the culprit, so I disabled them via Settings->Extensions and the problem went away.