<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: lesheess</title>
    <description>The latest articles on DEV Community by lesheess (@lesheess).</description>
    <link>https://dev.to/lesheess</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4272533%2F3b15c888-b0e1-443f-9dec-f01d28119f7a.png</url>
      <title>DEV Community: lesheess</title>
      <link>https://dev.to/lesheess</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lesheess"/>
    <language>en</language>
    <item>
      <title>My Mac's menu bar has eyes, and they dance to whatever is playing</title>
      <dc:creator>lesheess</dc:creator>
      <pubDate>Sun, 29 Nov 2026 15:19:57 +0000</pubDate>
      <link>https://dev.to/lesheess/my-macs-menu-bar-has-eyes-and-they-dance-to-whatever-is-playing-3jlp</link>
      <guid>https://dev.to/lesheess/my-macs-menu-bar-has-eyes-and-they-dance-to-whatever-is-playing-3jlp</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1z15fauftcuh587zv5d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp1z15fauftcuh587zv5d.gif" alt="Madam, one of Roomie's two roommates, dancing to music in the menu bar" width="640" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rules
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;One file, &lt;code&gt;main.swift&lt;/code&gt;, about 2,600 lines.&lt;/li&gt;
&lt;li&gt;No Xcode. Only the Command Line Tools: the build script calls &lt;code&gt;swiftc&lt;/code&gt; twice and &lt;code&gt;lipo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;No image assets. Every eye, lid, heart and note, and even the app icon, is drawn with Core Graphics at runtime.&lt;/li&gt;
&lt;li&gt;No network code, and no permissions unless you ask for dancing to the beat.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; ARCH &lt;span class="k"&gt;in&lt;/span&gt; arm64 x86_64&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  swiftc -O -target &lt;span class="nv"&gt;$ARCH&lt;/span&gt;-apple-macos13.0 main.swift -o Roomie-&lt;span class="nv"&gt;$ARCH&lt;/span&gt; \
    -framework AppKit -framework IOKit -framework ServiceManagement
&lt;span class="k"&gt;done&lt;/span&gt;
lipo -create Roomie-arm64 Roomie-x86_64 -output Roomie.app/Contents/MacOS/Roomie
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Hearing what the Mac plays
&lt;/h2&gt;

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;desc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CATapDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stereoGlobalTapButExcludeProcesses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;myProcessObject&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;UUID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;isPrivate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="n"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;muteBehavior&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;unmuted&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;tap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AudioObjectID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kAudioObjectUnknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;AudioHardwareCreateProcessTap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;tap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;aggregate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="n"&gt;kAudioAggregateDeviceNameKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Roomie ear"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;kAudioAggregateDeviceUIDKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;UUID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;kAudioAggregateDeviceIsPrivateKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;kAudioAggregateDeviceTapAutoStartKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;kAudioAggregateDeviceTapListKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;kAudioSubTapUIDKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;desc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;uuidString&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AudioObjectID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kAudioObjectUnknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nc"&gt;AudioHardwareCreateAggregateDevice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;aggregate&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;CFDictionary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// then AudioDeviceCreateIOProcIDWithBlock(...) and AudioDeviceStart(...)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;One gotcha cost me an evening. Without &lt;code&gt;NSAudioCaptureUsageDescription&lt;/code&gt; in &lt;code&gt;Info.plist&lt;/code&gt;, nothing fails: every call returns &lt;code&gt;noErr&lt;/code&gt;, the buffers arrive on time, and they are full of perfect silence. macOS never even asks the user for permission.&lt;/p&gt;

&lt;h2&gt;
  
  
  Finding the beat
&lt;/h2&gt;

&lt;p&gt;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".&lt;/p&gt;

&lt;p&gt;Twice a second, it looks at the last 8 seconds of onset strength, resampled at 200 Hz:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Tempo.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Phase.&lt;/strong&gt; A comb at that period slides across the onsets; recent beats count more than old ones.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Glide.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;On test tracks it lands within 0.07 of a beat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Right but jittery looks worse than late but smooth
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;What fixed it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A clock of its own.&lt;/strong&gt; The dance runs on a smooth beat clock that glides towards the tracker instead of reading it directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hysteresis.&lt;/strong&gt; They start dancing at confidence 0.4 and keep dancing down to 0.18.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency.&lt;/strong&gt; The output device's latency is added, so a move lands when you hear the beat, not when the samples arrive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Silence.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  60 fps in the menu bar for 2% CPU
&lt;/h2&gt;

&lt;p&gt;Setting &lt;code&gt;NSStatusItem.button.image&lt;/code&gt; every frame cost 16% CPU. A &lt;code&gt;CALayer&lt;/code&gt; inside the status button, fed a &lt;code&gt;CGImage&lt;/code&gt; 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  The bug: dead on arrival on macOS 13
&lt;/h2&gt;

&lt;p&gt;Roomie's minimum is macOS 13. Dancing to the beat needs 14.2, and every use of it sits behind &lt;code&gt;#available(macOS 14.2, *)&lt;/code&gt;. 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".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nm -m&lt;/code&gt; on the binary said:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(undefined) external _OBJC_CLASS_$_CATapDescription (from CoreAudio)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It says &lt;code&gt;external&lt;/code&gt;, not &lt;code&gt;weak external&lt;/code&gt;. The functions such as &lt;code&gt;AudioHardwareCreateProcessTap&lt;/code&gt; 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. &lt;code&gt;#available&lt;/code&gt; guards code paths. It does not guard the linker.&lt;/p&gt;

&lt;p&gt;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:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;swiftc ... -Xlinker -weak_framework -Xlinker CoreAudio
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the build script now refuses to produce a binary with the problem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; nm -m Roomie-arm64 &lt;span class="o"&gt;|&lt;/span&gt; grep -v weak &lt;span class="o"&gt;|&lt;/span&gt; grep -q &lt;span class="s1"&gt;'OBJC_CLASS_\$_CATap'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"CATapDescription linked strongly"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your deployment target is older than your SDK, run &lt;code&gt;nm -m&lt;/code&gt; over the binary before a release and look for strong references to anything newer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: the promo video is rendered by the app
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Roomie --dancefilm out.mp4&lt;/code&gt; renders a vertical video with &lt;code&gt;AVAssetWriter&lt;/code&gt;, 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Download (free, macOS 13 or later, Apple silicon and Intel): &lt;a href="https://lesheess.github.io/small-living-things/" rel="noopener noreferrer"&gt;https://lesheess.github.io/small-living-things/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Code: &lt;a href="https://github.com/Lesheess/small-living-things" rel="noopener noreferrer"&gt;https://github.com/Lesheess/small-living-things&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Roomie isn't notarized yet, so the first launch needs right-click, Open (or Open Anyway in Privacy &amp;amp; Security on macOS 15 and later).&lt;/p&gt;

&lt;p&gt;I built Roomie together with Claude, which wrote much of the code and helped write this post.&lt;/p&gt;

</description>
      <category>swift</category>
      <category>macos</category>
      <category>showdev</category>
      <category>audio</category>
    </item>
  </channel>
</rss>
