Aliases for macOS User Defaults

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.

One thought on “Aliases for macOS User Defaults

Leave a Reply

Your email address will not be published. Required fields are marked *