lsregister: a valuable undocumented command for LaunchServices

Among the many important tasks carried out by LaunchServices is associating different types of documents with the apps which should be used to open them. If you read my short article about dealing with a situation in which the wrong version of an app becomes the default, you’ll have seen the Postscript in which Jeff Johnson suggested using a command lsregister. Yet if you try its man page, you’re out of luck: it doesn’t appear to have one. Indeed, this valuable command is essentially undocumented.

Type its full path
and you’ll be told tersely about its usage. A copy of this is available here, and that’s the closest that Apple feels you should get to any documentation.

Useful lsregister commands follow one of two forms:
lsregister [options] [path]
which register and unregister the item (app, usually) specified by the path, and
lsregister [options] [-apps domainlist] [-libs domainlist] [-all domainlist]
which act on the LaunchServices database for the given types (apps, libs, all) and domains. Domains are usually specified as a list of letters:
is the complete set, covering user (your Home folder), system, local and network.

Get LaunchServices to check registered apps

In recent versions of macOS, a new option -gc has been added to get LaunchServices to rescan different domains for app info and garbage collect its database. For example,
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -gc -R -v -apps u
checks relevant folders in your Home folder, including ~/Applications, for apps which it needs to add to its database. Again you can widen this to a full scan of apps using
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -gc -R -v -apps u,s,l

Using the -v verbose option, you may see lots of error -10811 reports where LaunchServices is unable to find any relevant information. These can be ignored normally.

Reset the LaunchServices database

You can do this using a utility such as OnyX, or on older versions of macOS with lsregister in a command like
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain u -domain s -domain l -v
If you wish, you can add an option to scan default locations to seed the new database, using

The more recent syntax should work more reliably in Sierra and later, and takes the form
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -apps u
to affect just the user domain.

For more extensive rebuilds, widen its domains, for example with
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -apps u,s,l
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -all u,s,l
again using -seed to scan default locations to seed the new database if you wish.

Register an app with LaunchServices

You shouldn’t ever have to do this, but you should be able to register an app with a command such as
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -R -f pathname
where pathname is the path and name of the app.

Unregister an app with LaunchServices

To remove an existing database entry for an app, such as a version that you don’t want to launch, try
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -R -f -u pathname
where pathname is the path and name of the app.

I hope that these prove useful when you’re trying to fix problems with LaunchServices and its database.