Skip to content

hs.spaces: fix spaces interaction in macOS 27 - #3904

Open
SirVer wants to merge 4 commits into
Hammerspoon:masterfrom
SirVer:spaces-macos27-windowmanager
Open

SirVer wants to merge 4 commits into
Hammerspoon:masterfrom
SirVer:spaces-macos27-windowmanager

Conversation

@SirVer

@SirVer SirVer commented Oct 12, 2026

Copy link
Copy Markdown

I updated to macOS 27 over the weekend and my automatic workspace switching did no longer work. I did a round of AI investigation and put together this fix. It is written by AI, reviewed by me and tested on my machine and works. It is carefully written so older OS versions should be unaffected. It is presented for your consideration for merging, but I am not angry if you do not want to merge this.

Root cause:

On macOS 27 the Dock no longer hosts the Mission Control accessibility tree. While Mission Control is showing, the Dock still exposes its mc group, but as an empty stub; the mc.display groups are now direct children of the WindowManager application (com.apple.WindowManager). findSpacesSubgroup() therefore never found a display and gotoSpace, removeSpace, addSpaceToScreen and missionControlSpaceNames all failed with "no display with specified id found".

getMissionControlGroup() now returns the element that actually holds the mc.display groups: the Dock's mc group if populated (macOS 26 and earlier), otherwise the WindowManager application element, and nil while the tree is not populated yet, so findSpacesSubgroup's existing poll waits for it instead of failing on the stub.

Open/closed detection keeps using the presence of the Dock mc group, which still only exists while Mission Control is showing; the WindowManager element is always valid and cannot be used for that.

Adds Lua tests for the lookup (Dock layout, WindowManager layout, empty stub, closed).

Fixes #3897

On macOS 27 the Dock no longer hosts the Mission Control accessibility
tree. While Mission Control is showing, the Dock still exposes its `mc`
group, but as an empty stub; the `mc.display` groups are now direct
children of the WindowManager application (com.apple.WindowManager).
findSpacesSubgroup() therefore never found a display and gotoSpace,
removeSpace, addSpaceToScreen and missionControlSpaceNames all failed
with "no display with specified id found".

getMissionControlGroup() now returns the element that actually holds
the `mc.display` groups: the Dock's `mc` group if populated (macOS 26
and earlier), otherwise the WindowManager application element, and nil
while the tree is not populated yet, so findSpacesSubgroup's existing
poll waits for it instead of failing on the stub.

Open/closed detection keeps using the presence of the Dock `mc` group,
which still only exists while Mission Control is showing; the
WindowManager element is always valid and cannot be used for that.

Adds Lua tests for the lookup (Dock layout, WindowManager layout, empty
stub, closed).

Fixes Hammerspoon#3897

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request does not contain a valid label. Please add one of the following labels: ['pr-fix', 'pr-change', 'pr-feature', 'pr-maintenance']

@SirVer SirVer changed the title hs.spaces: find the Mission Control AX tree in WindowManager on macOS 27 hs.spaces: fix spaces interaction in macOS 27 Oct 12, 2026
mit-bach and others added 2 commits October 22, 2026 17:06
When Mission Control is reopened right after being closed (back to back
hs.spaces calls, e.g. addSpaceToScreen() followed by gotoSpace()), the
WindowManager on macOS 27 briefly exposes a partially built tree: the
Dock's `mc` stub is already back and WindowManager has some `mc.display`
groups, but not all of them, or one without its `mc.spaces` group yet.
Observed on 27.0.1 with three displays: one `mc.display` (of three) with
no spaces bar, about 60ms after the reopen.

findSpacesSubgroup() only waited for the Mission Control group itself
and then did a single pass, so it failed straight away with "no display
with specified id found" or "unable to locate mc.spaces group for
display". It now retries the whole lookup within the same 2 second
window. The success path is unchanged; lookups that cannot succeed now
return their error after that window instead of immediately.

The single pass is split out as spacesSubgroupFrom() and exposed to the
test suite like _missionControlGroupFrom. The fake AX element used by
the tests now returns a copy of its children, as hs.axuielement does,
since the lookup consumes that table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
missionControlSpaceNames() turns the Mission Control button descriptions
("exit to Desktop", "exit to full screen Safari") into space names with
templates read from the Dock's localized Accessibility.strings.

On macOS 27 the buttons come from WindowManager, which looks these
strings up with CFBundleCopyLocalizedString(mainBundle, key, default,
"Accessibility"). WindowManager.app has no Accessibility table (as of
27.0.1 its .lproj folders are empty and it only ships Localizable and
InfoPlist loctables), so it always uses the English defaults "exit to %@"
and "exit to full screen %@", while Dock.app still ships the localized
templates. For any non-English user the templates never matched and the
full description was returned as the name.

Try the English defaults after the localized templates, so names that
matched before still match the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mit-bach

Copy link
Copy Markdown

Tested this on macOS 27.0.1 (26A434) with three displays; the WindowManager lookup works. Found two gaps (a partial tree right after reopening Mission Control, and WindowManager's space buttons always using English names) and opened a PR against your branch with fixes and tests: SirVer#1

hs.spaces: handle partial Mission Control tree and English space names on macOS 27
@SirVer

SirVer commented Oct 24, 2026

Copy link
Copy Markdown
Author

@mit-bach Your changes look good to me; on my system they did not make a differences, but feel generally more defensive, so I merged them in.

I think this branch should go in.

@irobertson

Copy link
Copy Markdown

I've applied the changes in this PR to my own local install, and it's fixed the issues with OS 27. I look forward to seeing this merged, and I give my thanks to @SirVer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hs.spaces: Mission Control accessibility tree moved from the Dock to WindowManager on macOS 27

3 participants