Bit-perfect Apple Music on macOS — detects the live audio format and auto-switches your DAC sample rate. Menubar app + Alfred workflow.
Apple Music on macOS does not automatically reconfigure your output device's sample rate to match the source material. Play a 192 kHz / 24-bit hi-res master through a DAC stuck at 44.1 kHz / 16-bit and macOS silently downsamples it. Lossless becomes lossy.
This project fixes that.
A small background daemon tails the system log for MediaToolbox format reports from Music.app, parses the live codec / sample rate / bit depth, and (optionally) re-configures the active output device via CoreAudio HAL to match — bit-perfect playback, automatically. The same daemon also drives a SwiftUI now-playing card in the menubar and a set of Alfred keywords for quick inspection / switching.
Now-playing card (left-click the menubar icon). Format line shows the live codec / rate / depth as decoded by Music.app. The footer shows the output device's currently-configured physical format.
Action menu (right-click). Toggle auto-follow, switch the menubar between icon and live sample-rate text, jump to any Alfred keyword.
Switch Format submenu — full capability list of your DAC, populated from CoreAudio HAL. Pick any to apply immediately.
nplog keyword in Alfred — inspect the apply log, current device format, and recent applies. Enter to copy, ⌘⏎ to clear.
- macOS 13+ (Swift literal regex,
kAudioObjectPropertyElementMain) - Alfred 5 with Powerpack
- A DAC or audio interface that exposes multiple sample-rate formats (otherwise there's nothing to switch between)
- Download the latest
alfred-apple-music-format.alfredworkflowfrom Releases - Double-click to import into Alfred
- In Alfred, type
nponce — the LaunchAgent installs automatically on first run
The menubar icon (or sample-rate text, if you toggle that) appears immediately. No further setup.
| Keyword | What it does |
|---|---|
np |
Show currently-playing track + format. ⏎ copies a one-line summary to clipboard. |
audio |
List all formats your default output device supports. ⏎ to switch. |
npauto |
Toggle auto-follow: when on, daemon switches DAC format on every track change. |
nplog |
View / clear the apply log (history of format switches). |
npmenu |
Show / hide the menubar icon (daemon keeps running in background). |
npstop |
Stop the background daemon. Stays gone until npstart. |
npstart |
Resume the daemon after npstop. |
- Switch Format — manually pick from your DAC's full capability list (e.g. 16/24/32-bit at 44.1 / 48 / 88.2 / 96 / 176.4 / 192 / 352.8 / 384 / 705.6 / 768 kHz, depending on hardware)
- Disable / Enable Auto-Follow Song Format — same as
npauto - Show Sample Rate in Menubar — replace the music note icon with live text (e.g.
48 kHz) - Open in Alfred — quick jump to any keyword
- Hide Menubar Icon — same as
npmenu - Quit — terminate the menubar UI (daemon keeps running)
When Auto-Follow Song Format is on (default after install), the daemon:
- Tails Music.app's
MediaToolboxformat reports from the system log (/usr/bin/log stream). - On every track change, parses sample rate + bit depth.
- Calls CoreAudio HAL (
kAudioStreamPropertyPhysicalFormat) to set the default output device to that exact format. - Logs the change to
~/Library/Caches/com.ariestwn.apple-music-audio-format/apply.log.
If your DAC doesn't expose the exact bit depth at the requested rate, it falls back: 24 → 32 → 16. Your DAC's native rate ladder is the ceiling — if Music plays a 96 kHz track but your DAC tops out at 48 kHz, the daemon picks 48.
Disable it (via npauto or the action menu) if you'd rather use Audio MIDI Setup manually, or if format switches cause audible clicks on your hardware.
The daemon needs three macOS permissions. Two prompt automatically; the third may need a manual nudge.
What for: read track name / artist / album / sample rate from Music.app via AppleScript. Auto-prompted: yes — first time the daemon queries Music.app.
What for: drive shuffle / repeat menu items via UI scripting (Music.app's own shuffle enabled / song repeat AppleScript properties no longer work on recent macOS).
Auto-prompted: yes — first time you click the shuffle / repeat button on the popover.
What for: required by System Events to actually invoke menu items in another app. Without it, shuffle / repeat silently no-op with error -1719 (assistive access).
Auto-prompted: yes — programmatic prompt on first shuffle / repeat click. If it doesn't appear (e.g. you previously dismissed it), open System Settings → Privacy & Security → Accessibility and enable Apple Music Audio Watcher manually.
- Some menubar utilities hide unsigned items by default (Bartender, Ice, etc.). The app is ad-hoc signed (no paid Apple Developer ID) so they treat it as "unidentified". Add an exception or restart the utility.
- Check the daemon is alive:
pgrep -fl "Apple Music Audio Watcher". Should print one process. - Daemon running but icon hidden: type
npmenuin Alfred → Show Icon (clears the manual hide flag).
- Orphan process from a previous install. Force-kill — KeepAlive will respawn within seconds:
pkill -9 -f "Apple Music Audio Watcher"
Stale Accessibility attribution after a rebuild — macOS sometimes caches the old signature path. Reset and re-grant:
tccutil reset Accessibility com.ariestwn.apple-music-audio-formatThen click any control button — the prompt re-appears with the current bundle path.
- It's a "shared track" — Apple Music streaming, not in your library. The daemon's parsing is correct; Apple is actually streaming AAC for that path. Add the track to your library, or download it for full Lossless.
- Lossless disabled in Music's settings: Music → Settings → Playback → Audio Quality → Lossless.
- Open
nplogand check the Log summary — ifapply.loghas recent successful applies but the DAC didn't move, the device is probably in exclusive mode (another app holding it). Close other audio apps and try again, or use theaudiokeyword to switch manually. - DAC doesn't expose the requested rate. The
audiokeyword shows what it actually supports.
This was a known issue and is fixed: npstop writes a daemon.off flag that prevents the auto-heal in np from re-bootstrapping. Use npstart to resume. If you're still seeing it, you're on an older build — re-import the latest .alfredworkflow.
launchd reentrancy after a rapid bootout/bootstrap. The install script has a retry loop, but if it persists:
launchctl bootout "gui/$(id -u)/com.ariestwn.apple-music-audio-format" 2>/dev/null
sleep 6
~/Documents/Alfred/Alfred.alfredpreferences/workflows/<workflow-uuid>/install.sh(Alfred → right-click workflow → Open in Finder reveals the workflow folder.)
Artwork comes from the iTunes Search API, matched by title + artist. Generic titles can collide. The next track change re-resolves it. If a specific track is consistently wrong, that's an iTunes Search ranking quirk, not a daemon bug.
"Real Mem" inflates by shared framework pages (AppKit / SwiftUI / CoreFoundation) that every macOS process loads — they don't cost extra RAM. The actual private footprint is ~50 MB, which vmmap --summary <pid> | grep "Physical footprint" reveals.
One Mach-O binary (Apple Music Audio Watcher), three roles:
- Background daemon — tails
/usr/bin/log streamfiltered to Music.app's MediaToolbox subsystem; parses[FormatID / SampleRate / BitDepth / Rendition]lines fromFigStreamPlayer; writes JSON cache + drives auto-apply via CoreAudio HAL. - Menubar UI — same process;
NSStatusItemleft-click →NSPanelhosting a SwiftUI now-playing card with a.menumaterial vibrancy blur. Right-click → actionNSMenu. - Alfred CLI helper (
audio_format) — small standalone binary; lists / switches CoreAudio physical formats for theaudioScript Filter and the auto-apply path.
Runs as a user LaunchAgent (com.ariestwn.apple-music-audio-format) with KeepAlive=true, so the daemon respawns on crash.
Cache files: ~/Library/Caches/com.ariestwn.apple-music-audio-format/
nowplaying.json— current format snapshot, consumed by Alfrednpapply.log— history of successful auto-appliesartwork.jpg— cached 200×200 album artwatcher.err/watcher.out— LaunchAgent stdio for debugging
Settings flags: ~/Library/Application Support/com.ariestwn.apple-music-audio-format/
autoapply.off— disables auto-followmenubar.off— hides the status icon (daemon stays alive)daemon.off—npstopwas invoked; auto-heal inshow.shrespects thisdisplay.mode—icon(default) orformatfor the menubar item content
git clone https://github.com/ariestwn/alfred-apple-music-format.git
cd alfred-apple-music-format
./build.sh # compile + assemble + zip
open "dist/Apple Music + Audio Format.alfredworkflow" # import into Alfredbuild.sh produces a universal binary (arm64 + x86_64). workflow/install.sh thins to the host arch on import — distribution stays cross-platform, installed footprint is half-size native.
In Alfred: right-click the workflow → Open in Finder → run uninstall.sh. Then delete the workflow from Alfred.
If you skipped uninstall.sh and the daemon still respawns, manual cleanup:
launchctl bootout "gui/$(id -u)/com.ariestwn.apple-music-audio-format" 2>/dev/null
rm -f ~/Library/LaunchAgents/com.ariestwn.apple-music-audio-format.plist
rm -rf ~/Library/Application\ Support/com.ariestwn.apple-music-audio-format
rm -rf ~/Library/Caches/com.ariestwn.apple-music-audio-formatOptionally reset all TCC permissions tied to this app:
tccutil reset All com.ariestwn.apple-music-audio-formatMIT. See LICENSE.



