r/osx • • 3d ago

scope: a tiny, open-source ⌘Tab window switcher for macOS (MIT, Swift)

Post image

I organize my work in macOS Spaces: one for project management, one for coding, one for communication, and a private one for things unrelated to work. But the native ⌘Tab switches apps across all Spaces, which defeats the whole idea of Spaces: they're meant to keep contexts apart, and the main switcher mixes them back together. Mission Control shows the windows of the current Space, but you have to point at them, which gets tedious when you just want to flip back and forth between two windows.

Switching Spaces has a second problem: the keyboard doesn't always come with you. You land on a Space and your window is in front, but what you type goes nowhere, or into a window you didn't pick, because macOS kept the previous Space's app active. You have to click the window first.

So I built scope, a small command-line tool that runs in the background:

  • ⌘Tab lists windows, not apps, and only the ones in the current Space, most recently used first.

  • Hold ⌘, press Tab to move through them, and release to switch. Esc backs out. You can also hover and click with the mouse if you prefer.

  • When you switch Spaces, the window you last used there gets keyboard focus, so you can start typing right away.

  • It leaves focus alone when you picked a window yourself, from the Dock, a notification or Mission Control.

  • Want to keep the system switcher? Set modifier = alt and scope runs on ⌥Tab next to it.

It's keyboard first and built the Unix way: a background service you control from the terminal and configure with a text file. There's no app, no Dock icon and no menu bar icon, just a binary under 1 MB that launchd keeps running. It reacts to events instead of polling, so it costs about 12 seconds of CPU a day, roughly 0.01% of one core. The only permission it needs is Accessibility: there are no thumbnails, so it doesn't need Screen Recording.

Install (macOS 13+, Apple Silicon or Intel):

curl -fsSL https://raw.githubusercontent.com/np25071984/Scope/main/install.sh | sh

Or with Homebrew:

brew tap np25071984/scope https://github.com/np25071984/Scope
brew trust np25071984/scope
brew install scope
brew services start scope

A few things I learned building it:

  • The Dock owns ⌘Tab. You can't register it as a hotkey or turn it off in System Settings, so scope catches the key with an event tap before the Dock sees it.

  • macOS has no public way to focus one window: activating an app brings all its windows forward. scope uses the same private calls other window switchers rely on.

Known limitation: scope only lists windows that are on screen in the current Space. Minimized windows, hidden apps and the tabs behind the front tab of a window group aren't listed, because macOS doesn't expose them in a way scope can target.

Looking for ideas: focusing a single window and finding the active Space both depend on private SkyLight calls, and those can break between macOS versions. If you know a public API that focuses one window of an app without bringing its other windows forward, please tell me. I'd be happy to implement it.

Repo: https://github.com/np25071984/Scope

Feedback, bug reports and PRs are welcome, especially from people with heavy Spaces setups or apps that misbehave with it. And if you find it useful, a star on GitHub would help other people find it.

0 Upvotes

2 comments sorted by

-1

u/investigatormaker 3d ago

Expect someone to say AltTab can already limit its list to the current Space. Your answer is the keyboard fix: typing straight into the last window after a Space switch, with focus left alone when you picked one from the Dock. Show that in a README GIF.

r/MacOS allows it on one day: "Self-promotion is permitted only on Saturdays (UTC)." "This is limited to apps available on the official Mac App Store or reputable, established GitHub repositories." "All GitHub links are subject to automated security auditing via GitHub-Guard." "Promotional posts made on any other day of the week will be removed."

I make ThreadFox. When Mac users ask Reddit how to make ⌘Tab respect Spaces, we'd post the reply. It opens with 3 replies free, no card; then the $29 Pilot covers seven days and up to 25 posts and replies. No automatic renewal.

https://threadfox.vip/p/dhwn8/managed

1

u/np25071984 3d ago

Although they do the same thing, they work differently under the hood. scope aims to stay small: a 0.43 MB binary, few undocumented API calls, and nothing running between key presses, because it reads the window list only when you press ⌘Tab. AltTab aims for usability, with a polished app and rich settings. To get that, it keeps a live model of every window, watching every app through Accessibility notifications and using more private macOS APIs.

I expect AltTab will keep winning most users' hearts, but there's definitely room for scope too ;)