Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am able to use mdls to show the Uniform Type Identifier (UTI) for an arbitrary file as well as the hierarchy of types that are supersets of a specific UTI.

mac:~ mike$ mdls -name kMDItemContentType -name kMDItemContentTypeTree foo.ksh
kMDItemContentType     = "public.ksh-script"
kMDItemContentTypeTree = (
    "public.ksh-script",
    "public.shell-script",
    "public.script",
    "public.source-code",
    "public.plain-text",
    "public.text",
    "public.data",
    "public.item",
    "public.content"
)
mac:~ mike$ mdls -name kMDItemContentType -name kMDItemContentTypeTree foo.command
kMDItemContentType     = "com.apple.terminal.shell-script"
kMDItemContentTypeTree = (
    "com.apple.terminal.shell-script",
    "public.shell-script",
    "public.script",
    "public.source-code",
    "public.plain-text",
    "public.text",
    "public.data",
    "public.item",
    "public.content"
)

Are there any tools that can show which Apps have registered for a particular UTI other than trial and error?

It's clear from inspection that the foo.command file will be opened by Terminal.app, but it's not at all clear that foo.ksh currently belongs to TextEdit.app.

I'd like to be able to read the Mac OS X Launch Services database directly without actually resorting to using open to see which app is chosen on a per UTI basis. It would be like having --preview --verbose switches to get open to tell me what is would do rather than doing it.

Even better would be a way to list all apps that could open that UTI, even if they are not the preferred app.

To get this secondary information, I have to create or find a file for each type of interest and use Finder to manually show which apps could open that UTI.

enter image description here

I would really like to be able to access this data programatically from the terminal.

share|improve this question
    
The zsh completion seems interesting, but I don't see how to get that as stdout. I'll look into the AppApplications source code and see if the binary works on Lion or I can get it compiled. It's a great pair of leads - thanks! – bmike Aug 30 '11 at 22:59
up vote 5 down vote accepted

Andrew Mortensen’s duti is a CLI that will list UTI handlers:

  • -d <uti> lists the default handler;
  • -l <uti> lists all registered handlers.

See the man page for duti.

EDIT: as Lri points out in this answer, duti does not seem to list all possible applications (possibly because it does not take account of UTI inheritance? That would be a matter for further inquiry). His recommended solution, AllApllications would obviously be a better answer.

share|improve this answer
    
It's missing some apps that would be displayed in the open with menu though. – user495470 Oct 12 '11 at 12:50
    
Very odd. Could you tell me which ones it is missing? – kopischke Oct 12 '11 at 22:18
    
I edited my answer in the other question to include example output from duti. – user495470 Oct 13 '11 at 13:25
    
While duti is nicely written, it now uses deprecated APIs. I recommend to take a look at developer.apple.com/library/prerelease/mac/documentation/Carbon/… – Mugen Aug 27 '15 at 6:28
    
OK - installing this by homebrew knocks a home run. Thanks so much! – bmike Sep 22 '15 at 17:16

You can use this command to examine the launch services database. The -dump option gives you the entire database, then you can pipe this into grep and search for whatever you like.

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -n7 'your search string'

share|improve this answer
    
I'll probably need to ask a follow on question how to process this dump to spit out the app bundle or the location of the specific mdimporter file that parses a specific kMDItemContentType - but this has helped greatly. Thank you – bmike Sep 22 '15 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .