Roomie is a pair of eyes that lives in your Mac's menu bar. They follow the pointer, squash when you poke them, doze off when you leave, and now and then pop out of the notch to ask you to look away from the screen. Since the last release they also dance when music plays: on the beat, whatever is playing it. Spotify, a browser tab, a YouTube video.
It's free, and the whole app is one Swift file. Here is how the dancing works, plus a bug that made the app die at launch for everyone on macOS 13, which I only found because a friend tried to install it on an old Intel MacBook.
The rules
- One file,
main.swift, about 2,600 lines. - No Xcode. Only the Command Line Tools: the build script calls
swiftctwice andlipo. - No image assets. Every eye, lid, heart and note, and even the app icon, is drawn with Core Graphics at runtime.
- No network code, and no permissions unless you ask for dancing to the beat.
for ARCH in arm64 x86_64; do swiftc -O -target $ARCH-apple-macos13.0 main.swift -o Roomie-$ARCH \ -framework AppKit -framework IOKit -framework ServiceManagement done lipo -create Roomie-arm64 Roomie-x86_64 -output Roomie.app/Contents/MacOS/Roomie Hearing what the Mac plays
Since macOS 14.2, Core Audio can tap the system output. You describe a tap, create it, then build a private aggregate device whose input is that tap:
let desc = CATapDescription(stereoGlobalTapButExcludeProcesses: [myProcessObject]) desc.uuid = UUID() desc.isPrivate = true desc.muteBehavior = .unmuted var tap = AudioObjectID(kAudioObjectUnknown) AudioHardwareCreateProcessTap(desc, &tap) let aggregate: [String: Any] = [ kAudioAggregateDeviceNameKey: "Roomie ear", kAudioAggregateDeviceUIDKey: UUID().uuidString, kAudioAggregateDeviceIsPrivateKey: true, kAudioAggregateDeviceTapAutoStartKey: true, kAudioAggregateDeviceTapListKey: [[kAudioSubTapUIDKey: desc.uuid.uuidString]], ] var device = AudioObjectID(kAudioObjectUnknown) AudioHardwareCreateAggregateDevice(aggregate as CFDictionary, &device) // then AudioDeviceCreateIOProcIDWithBlock(...) and AudioDeviceStart(...) The IO block mixes the sound down to mono into a ring buffer of 8,192 samples, under two tenths of a second at 48 kHz. That is all the app ever holds. Nothing is recorded or saved.
One gotcha cost me an evening. Without NSAudioCaptureUsageDescription in Info.plist, nothing fails: every call returns noErr, the buffers arrive on time, and they are full of perfect silence. macOS never even asks the user for permission.
Finding the beat
For every frame, the tracker takes the latest 1,024 samples, applies a Hann window and runs an FFT with vDSP. Onset strength is spectral flux: how much louder each frequency bin got since the last frame. The bins are weighted. Below 200 Hz counts six times (the kick), up to 1.5 kHz counts once, and above that only 0.3, because hi-hats on the off-beat drag the phase onto the "and".
Twice a second, it looks at the last 8 seconds of onset strength, resampled at 200 Hz:
- Tempo. Autocorrelation over the lags for 70 to 171 bpm, gently weighted towards 115 bpm, so it picks the tempo you would tap rather than half or double. A parabola through the peak and its two neighbours gives a lag finer than one sample.
- Phase. A comb at that period slides across the onsets; recent beats count more than old ones.
- Glide. If the new estimate is close to the running one, period and phase move halfway towards it. It only jumps when it was unsure or the tempo really changed.
On test tracks it lands within 0.07 of a beat.
Right but jittery looks worse than late but smooth
The first version was accurate and looked awful. Every re-estimate nudged the dance, so the eyes twitched. Whenever confidence dipped for a second, they stopped dancing and snapped back to following the pointer.
What fixed it:
- A clock of its own. The dance runs on a smooth beat clock that glides towards the tracker instead of reading it directly.
- Hysteresis. They start dancing at confidence 0.4 and keep dancing down to 0.18.
- Latency. The output device's latency is added, so a move lands when you hear the beat, not when the samples arrive.
- Silence. Browsers keep their audio stream open when you pause, so "is something playing" isn't enough. If the last 2,048 samples go quiet for half a second, the dance stops.
60 fps in the menu bar for 2% CPU
Setting NSStatusItem.button.image every frame cost 16% CPU. A CALayer inside the status button, fed a CGImage each frame, costs about 2% at 60 fps. On top of that, the face is only redrawn when a quantised signature of its state changes.
The bug: dead on arrival on macOS 13
Roomie's minimum is macOS 13. Dancing to the beat needs 14.2, and every use of it sits behind #available(macOS 14.2, *). A friend tried it on an Intel MacBook with Ventura. First came the Gatekeeper dialog, which is expected for an app that isn't notarized (right-click, Open). But past that, it would have died at launch anyway with dyld's "Symbol not found".
nm -m on the binary said:
(undefined) external _OBJC_CLASS_$_CATapDescription (from CoreAudio) It says external, not weak external. The functions such as AudioHardwareCreateProcessTap were weak-linked, but the class reference was strong, so dyld refused to start the binary on any system where the class doesn't exist. #available guards code paths. It does not guard the linker.
The fix is to weak-link the framework. CoreAudio exists on every Mac, and on older systems the symbols it lacks simply resolve to nil:
swiftc ... -Xlinker -weak_framework -Xlinker CoreAudio And the build script now refuses to produce a binary with the problem:
if nm -m Roomie-arm64 | grep -v weak | grep -q 'OBJC_CLASS_\$_CATap'; then echo "CATapDescription linked strongly"; exit 1 fi If your deployment target is older than your SDK, run nm -m over the binary before a release and look for strong references to anything newer.
Bonus: the promo video is rendered by the app
Roomie --dancefilm out.mp4 renders a vertical video with AVAssetWriter, frame by frame, through the same drawing code as the menu bar. The music is synthesised in code too: four on the floor at 112 bpm, a clap, hats, a disco bass and a little A-minor hook, so every move lands on a hit. No video editor was involved.
Try it
- Download (free, macOS 13 or later, Apple silicon and Intel): https://lesheess.github.io/small-living-things/
- Code: https://github.com/Lesheess/small-living-things
Roomie isn't notarized yet, so the first launch needs right-click, Open (or Open Anyway in Privacy & Security on macOS 15 and later).
I built Roomie together with Claude, which wrote much of the code and helped write this post.


