Pull iPhone Screen Time from Biome store on macOS 14+#6
Open
natewill wants to merge 1 commit into
Open
Conversation
On macOS 14 (Sonoma) and later, Apple stopped writing synced iPhone
/app/usage events into knowledgeC.db and moved them to the Biome
telemetry store at ~/Library/Biome/streams/restricted/App.InFocus/
(binary SEGB pages containing protobuf records). As a result,
screentime2csv.py only returned Mac-local rows even with Screen Time
"Share Across Devices" enabled.
This change adds a second source to screentime2csv.py so one script
produces a unified CSV covering both Mac and iPhone:
- Walks App.InFocus/{local,remote}/<peer-uuid>/ SEGB pages and extracts
(timestamp, bundle_id) events by pattern-matching the protobuf wire
format (field 4 fixed64 + field 6 length-delimited) — no external
protobuf schema or dependency required.
- Resolves peer UUIDs to device models via ~/Library/Biome/sync/sync.db
(DevicePeer table) so iPhone rows are labeled e.g. "iPhone (23D8133)".
- Merges consecutive same-app events per peer into sessions, extending
each closed session's end toward the next event in the stream (capped
at --biome-max-gap, default 300s) so short foreground bursts followed
by a gap still register as active use.
- New flags: --since, --no-knowledge, --no-biome, --biome-stream,
--biome-max-gap, --include-biome-local, --summary. Defaults keep the
previous behavior of reading knowledgeC, and additionally read Biome.
- The knowledgeC SQL query is unchanged; output schema is unchanged
(app, usage, start_time, end_time, created_at, tz, device_id,
device_model).
README updated with the new usage, flags, and a short explanation of
why Biome is needed on macOS 14+.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
screentime2csv.pyso one script produces a unified CSV covering both Mac and iPhone (plus any other synced Screen Time peers) on macOS 14+.app, usage, start_time, end_time, created_at, tz, device_id, device_model), so existing downstream analysis keeps working.Why
On macOS 14 (Sonoma) and later, Apple stopped writing synced iPhone
/app/usageevents intoknowledgeC.dband moved them to the Biome telemetry store at~/Library/Biome/streams/restricted/App.InFocus/remote/<peer-uuid>/— binary SEGB pages containing protobuf records.Before this change,
screentime2csv.pyreturned only Mac-local rows even when Screen Time → Share Across Devices was enabled, because theZSOURCE/ZSYNCPEERjoin it relies on no longer contains iPhone events. The/app/usagerows inknowledgeC.dball haveZSOURCE = NULLon modern macOS.What's in it
App.InFocus/{local,remote}/<peer-uuid>/pages and extracts(timestamp, bundle_id)events by pattern-matching the protobuf wire format (field 4fixed64start + field 6 length-delimited bundle). No external protobuf schema or dependency required.~/Library/Biome/sync/sync.dbDevicePeertable so iPhone rows are labeled e.g.iPhone (23D8133)and Macs asMac (...). Falls back toplatform-N/ bundle model if unknown.--biome-max-gapseconds (default 300), so short foreground bursts followed by a gap still register as active use. The last event in the stream just spans its observed range.--since—7d/24h/30m/ unix epoch--no-knowledge— skip the knowledgeC source (Mac-only runs)--no-biome— skip the Biome source--biome-stream— alternate stream name (defaultApp.InFocus;ScreenTime.AppUsageis the fallback on some installs)--biome-max-gap— seconds between events to still count as one session (default 300)--include-biome-local— also include this Mac's local Biome stream (usually redundant with knowledgeC)--summary— per-device top-apps summary to stderrknowledgeC→ Biome migration.The existing
knowledgeC.dbSQL query is untouched; Mac-local behavior is unchanged for users who pass--no-biome.Test plan
python3 screentime2csv.py -o output.csv --since 7d --summaryon a Mac + iPhone signed into the same iCloud account with Share Across Devices on:knowledgeC.dbcom.atebits.Tweetie2,com.burbn.instagram,com.google.ios.youtube,com.apple.mobilesafari,com.hammerandchisel.discord,com.spotify.client, …) attributed toiPhone (…)--no-biomeproduces the original behavior (Mac-only rows fromknowledgeC.db)--no-knowledgeproduces only Biome rowsNotes / caveats
~/Library/Biome/).--biome-streamlets you point at an alternate stream without a code change.🤖 Generated with Claude Code