Warning: private macOS internals. This was tested on macOS 27.0.1. This is not a supported API. Apple can change the file's location, format, permissions, or behavior in a future update. Editing or deleting "magic files" can have unintended consequences, including broken settings or lost data. The commands here only read the file. Don't edit it.
I rigged up a script to speak to me with the say command when a pull request was merged. It started barking at me during work meetings and phone calls. Not a great time to be interrupted by a script, mid-conversation or mid-presentation.
I had Work Focus on, but the script didn't know that.
I believe software should respect the choices of the person using it, especially about notifications. I like when my choices are respected too. That's a no-brainer for my work as well as my own scripts.
Your Mac keeps current Focus assertions and their history in one JSON file:
~/Library/DoNotDisturb/DB/Assertions.json
Read data[].storeAssertionRecords for current assertions, rather than the file's historical collections. With jq installed, this prints the mode identifiers:
jq -r '
.data[]
| .storeAssertionRecords // []
| .[]
| .assertionDetails.assertionDetailsModeIdentifier
' "$HOME/Library/DoNotDisturb/DB/Assertions.json"
No output means no records matched this query, not necessarily that Focus is off. A changed file format could also leave it with nothing to print. A read error doesn't mean Focus is off either.
A separate read returned com.apple.focus.work for Work Focus.
In an off/on/off check on macOS 27.0.1, the active-record collection was absent with Focus off. Turning on Do Not Disturb added it, with this mode identifier:
com.apple.donotdisturb.mode.default
Turning DND off removed that collection again.
The old records stay
The file also contained storeInvalidationRecords and storeInvalidationRequestRecords. Those were still there with Focus off. Searching the whole file for a mode's name would mix current assertions with historical records.
Read but don't edit
A script could use this as a reason to hold a nonurgent notification. A Work assertion still doesn't prove someone is working, or even sitting at the Mac.
The experiment covered a manual DND toggle on this Mac. Expiration, device syncing, and permissions in other script runners weren't tested.
Keep it read-only and let macOS manage Focus.