Reverse Engineering macOS Spaces with an AI Agent¶
August 14, 2026
I live in macOS Spaces. Calendar on one, comms on another, a Space per project, and a few more for whatever rabbit hole I'm in that week. Somewhere around Space six it stops being a workflow and starts being a guessing game. Desktop 3... no, 4... where did my email go? Apple gives you numbers, and numbers are not a memory system.
There's an app called SpaceJump that fixes this. It's $9.99, it's nice, and it lets you name your Spaces. Its big claim is that it's the only app that shows your custom names inside Mission Control on Apple Silicon without disabling SIP.
I could have just bought it. Instead I pointed Claude Code at the SpaceJump website and typed:
lets look at https://www.getspacejump.com/ and then lets come up with a plan to build a clone. osx native, probably swift?, spaces renaming
Two days later I had Spacewalker, a native Swift menu-bar app that does what I wanted, including the Mission Control trick. I didn't write a line of it. But the interesting part isn't that an agent wrote a Mac app. It's how it got there, because there's no API for any of this.
There is no Spaces API¶
Apple has never shipped a public API for Spaces. Not in 15+ years. Everything that touches Spaces rides on private SkyLight/CoreGraphics symbols that aren't documented and can change in any point release.
So the agent didn't start by writing an app. It started with a spike: a throwaway Swift package whose only job was to answer the scary questions on my actual machine (M-series, macOS 15, SIP on) before anything got built on top of them:
- Can we load the private
CGS…symbols at all? (Yes, loaded at runtime withdlsym, so nothing breaks at link time.) - Can we read the real Space layout? (Yes.
CGSCopyManagedDisplaySpacesgives you every display, every Space, and a UUID for each.) - Can we actually switch Spaces?
The UUIDs turned out to be the foundation. Names are keyed on the OS's own Space UUIDs, not on "Desktop 3", so they don't get scrambled when Spaces shift around. I named everything, rebooted, and the names came right back on the right Spaces. That's the exact case that breaks index-based tools.
Question three is where things got fun.
The agent lied to itself (and I caught it)¶
The obvious approach to switching is faking the keyboard shortcut: send Ctrl+→ and let macOS do its thing. The spike tried it, and these showed up in my terminal:
^[[1;5C
That's the literal escape code for Ctrl+→. The keystrokes were landing in my terminal as raw keys instead of switching anything. It turns out Sequoia ignores synthetic keystrokes for Space switching. The events go through, but the WindowServer won't act on them.
So the agent pivoted to a private API, CGSManagedDisplaySetCurrentSpace, ran it, re-read the Space topology, and reported back with a big green checkmark: switching works, no Accessibility permission needed, fully de-risked. 🎉
Except when I ran it, my screen didn't move. It just pulled Ghostty forward on the Space I was already on.
What happened is that the private call updates the WindowServer's internal idea of the current Space, so when the spike read that state back, it saw exactly what it had just written. The screen never changed. The agent had checked its work by asking the same system it had just changed. It agreed with itself.
To its credit, when I told it, it named the mistake right away: it had validated against the API's self-reported state instead of ground truth. That lesson ended up in the design doc in bold: do not validate a switch by re-reading this API — it self-confirms a lie.
I've been thinking about this one a lot since. It's not an AI problem exactly. People do this too. But an agent will do it very confidently, with a table of green checkmarks, and the only thing that caught it was a human looking at the actual screen.
What actually works¶
After a bit more digging, the answer was a little boring: AppleScript.
tell application "System Events" to key code 124 using control down
That one performed a real, animated Space switch. System Events sends keystrokes through the Accessibility path instead of the raw input path, and it sends the Control key as its own event before the arrow, which seems to be what the WindowServer's hotkey handler wants. Same keystroke, different door.
That gave us adjacent moves, but jumping from Space 1 to Space 6 meant five animated hops in a row. I said that was odd UX, and the fix was to turn on macOS's own "Switch to Desktop N" shortcuts (Ctrl+1 through Ctrl+9) by writing to com.apple.symbolichotkeys from code. They took effect live, no logout, and now a jump is one keystroke.
A few other macOS quirks we hit along the way:
- Spaces kept moving around. That was "Automatically rearrange Spaces based on most recent use," which is on by default. The app now turns it off (with your permission).
- Number keys in the switcher worked once and then never again. Every switch reported
ok, butokonly meant the AppleScript ran. Once the agent logged the actual Space before and after, the real bug showed up: a Ctrl+N sent while our app was grabbing focus got silently dropped. The fix was to give up focus, wait about 120ms, then switch. And that before/after check is now built into the app, so a switch that doesn't take gets reported instead of swallowed. - The switcher came up blank on first open, every time. Rows were sized from the view's width before layout had happened, when the width was still 0.

The Mission Control trick¶
This is the feature SpaceJump charges for, and the one I honestly didn't think we'd get. So I asked for a spike just to see if it was even possible.
Mission Control is drawn by the WindowServer at a very high window level. The trick turned out to be three pieces:
- Draw above it. A window at
CGShieldingWindowLevel()set to join all Spaces renders on top of Mission Control. The spike put a big ugly marker up there, I opened Mission Control, and there it was. - Know when it's open. The Dock process exposes Mission Control through the Accessibility tree, but only while it's open. So you poll the Dock's AX tree and watch for it to appear.
- Find each Space. Under Mission Control there's a "Spaces Bar" with an
AXButtonfor eachDesktop N, along with its exact on-screen rect, in order.
Map Desktop N to your Space name, paint a little pill at that rect on the overlay window, and your names float right onto the Mission Control thumbnails. As the Spaces bar expands, the pills ride along with it. All of it with SIP on.
The part I liked here was the back and forth. The agent built a probe to dump the Dock's AX tree, but you can't exactly run a command while Mission Control has taken over your screen. It wired the dump to a hotkey, I opened Mission Control, hit the key, and handed it the output. It had real data to build against instead of guesses.
The polish took longer than the hard part¶
Once everything worked, most of my time went into the stuff you'd expect: a dark theme with purple and lime green ("more rounded and osx like"), and a little heads-up display that flashes the Space name when you switch, like the volume HUD.

That HUD took more back and forth than the Mission Control overlay. Hammer Ctrl+→ a few times and it would show a trail of old names. The agent tried clearing it on macOS's Space-change notification, which made it worse. That notification fires after the new name is already showing, so it was erasing the right answer. The fix that stuck was blanking the HUD on the keypress itself, before the switch even happens, then filling in the name once the switch lands.
What I took away from it¶
- Spike first, always. The agent didn't write a line of app code until the private APIs were proven on my machine. Two of the three "obvious" approaches to switching were dead ends, and we found that out in an afternoon instead of after building a whole app on top of them.
- Verify against ground truth, not the system's own report. This came up twice: the phantom switch, and
result=okmeaning "the script ran" rather than "the screen moved." When an agent tells you something worked, ask how it knows. - The human in the loop is the one with eyes. I didn't write any Swift. My job was running things, looking at the screen, and saying "nope, that didn't actually switch." That turned out to be the most valuable thing I did.
The whole thing is on GitHub. The README says up front that Claude wrote all of it, and the design diary in PLAN.md keeps the dead ends in. It's free, and I've been using it every day since. My Spaces finally have names.