Occasionally I need to do something with user defaults from the command line. To do that, you use the appropriately named defaults
command. Unfortunately, if you use type defaults domain
to list all of the available commands, what you get is a bit hard to parse visually:
.GlobalPreferences_m, 182906152, ContextStoreAgent, Mixpanel, MobileMeAccounts, ScopedBookmarkAgent, ZoomChat, app.diagrams.DiagramsMac-setapp, app.kaleidoscope.v3, app.kaleidoscope.v3.ksdiff, app.soulver.appstore.mac, app.soulver.appstore.mac.revenuecat.etags …
To make things easier, I added these two aliases to my zshrc
file:
alias defaults-list="defaults domains | sed 's/, /\n/g'"
alias defaults-find="defaults-list | egrep $1"
The first alias, defaults-list
, splits each domain onto it’s own line, which is sort of useful visually, but mostly makes it easier to pipe the results into another command. All the second alias, defaults-find
, does is apply a grep
search to the domains list. So, if I was trying to find what the defaults domain for BBEdit was, I could do this:
> defaults-find bbedit
com.barebones.bbedit
Neat.
Great tip, thanks! Suggestion: I’d add the –ignore-case option to egrep to make the search case-insensitive.