lsregister: How Files Are Handled in Mac OS X

The lsregister command is used to query and manage the Launch Services database, or the database that is used to determine the default application used to open files of various types. lsregister is part of Core Services, and stored in /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support. To see the options available to lsregister, run the command with no operators: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister You can dump the database to the screen using the -dump option: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump You can then grep the database or redirect the output into a text file for parsing: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump > dump.txt Sometimes applications don’t open with a given file type. When this happens, you can quickly and easily check if the problem has to do with the launchservices database. To do so run the open command and define the application (using the -a option) followed by the app and then the file. For example, to open an XML file called daneel.xml in TextWrangler (assuming your working directory contains bob.xml): open -a bob.xml You can force an application to re-register file types for that application using the -f option followed by the application path. For example, to re-register Xcode: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /Developer/Applications/ You can also unregister a specific application using the -u option. To unregister Xcode you would use the -u option: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -u /Developer/Applications/ The lsregister command is actually just a front-end management tool for the ~/Library/Preferences/ file. The file’s contents can be read (in an unparsed form) using defaults: defaults read ~/Library/Preferences/ The launchservices database is also responsible for determining whether a file type is quarantined by default (and those files that are quarantined throw a message to users when opened for the first time). To disable such a feature: defaults write LSQuarantine -bool NO The database can become pretty large and unwieldy. There are applications registered in the local domain, system domain and each user’s domain. You can always clear these out using the following command, which also recursively rebuilds based on the output of a -lint option: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user To check the progress: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -v To set a specific application to open a file type, use the application’s domain out of the -dump output in an LSHandlerRoleAll and the file extension in an LSHandlerContentType in the LSHandlers array of, as follows (to change txt for Text Edit – aka defaults write LSHandlers -array '{ LSHandlerContentType = "txt"; LSHandlerRoleAll = ""; }'; You can also set the default application for a network protocol (e.g. smb://, rdp://, vnc://, http:// and https://). Because the options for lsregister leave one wanting in some ways (the commands to set file types to a specific application are a bit overly complicated one could argue), there is an awesome front end app from Andrew Mortensen, aptly called duti, available at With duti installed, the command to set the default browser for http would be: /usr/local/bin/duti -s http Note: When working with lsregister, one should first clear the state for that application: Finally, there’s a lot that Launch Services does and is involved in. For more information on LaunchServices, check out the Apple developer library information here.

5 thoughts on “lsregister: How Files Are Handled in Mac OS X”

  1. Great article!

    Do you know how to get lsregister to apply to all old and new users in OS X Lion? When I run the command it only works for the user context I run the command with. When I log onto a new or old user account and run the lsregister -dump command I can’t see the application I added with an the previous user account

    The command I run is like this.

    /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -R -f -v

  2. Hi, Thank you for the article. Very helpful. I would like to find out if there is a way to trust an app system wide to prevent running the command for new users as an example.

    Here is my script


    # Trust the MAU App

    echo ” – Trusting the MAU app”

    $lsregister_bin -R -f -trusted “/Library/Application Support/Microsoft/MAU2.0/Microsoft”

    # Trust the MAU Daemon app

    echo ” – Trusting the MAU Daemon app”

    $lsregister_bin -R -f -trusted “/Library/Application Support/Microsoft/MAU2.0/Microsoft AU”

Comments are closed.