Finding the icon of the default application from Terminal Say I have some files

simple_doc.txt
document.pdf
website.html


The .txt file opens with textEdit by default, the .pdf opens with Adobe Reader and the .html file will open in Google Chrome.

How can I find out this information from the command line? In particular, how can I find the icon of the default application for each of these files from the command line alone.

Thank you!
Background

There's a couple of tools you can use to analyze this situation. 


lsregister
defaults read


NOTE: lsregister is located here: 

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister


Navigating lsregister

You can use this command to navigate through the output from lsregister:

$ cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Versions/Current/Support/
$ lsregister -dump | less
...
...
    --------------------------------------------------------
    claim   id:            15536
            name:          Plain text document
            rank:          Default
            roles:         Viewer
            flags:         relative-icon-path  doc-type
            icon:          Contents/Resources/document.icns
            bindings:      .txt, .text, 'TEXT', text/plain
    --------------------------------------------------------
...
...


The structure is a little difficult to discern but you can look for strings such as .txt and take note of the lines occurring before it. 

To help us navigate this output, we can look in the Finder GUI for a type of file that we're interested in, for example a .txt file. Select it and then open up the info dialog about this particular file (⌘ + I). 

For example

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

With the details such as the "Kind: Plain Text Document" and what application it's associated with to open it, "TextEdit" we can then look through lsregister output and see if we cannot correlate things a bit.

For starters lets look for that "Kind: Plain Text Document".

$ lsregister -dump | grep -A5 -iE 'name:.*Plain text document'
        name:          Plain text document
        rank:          Default
        roles:         Viewer
        flags:         relative-icon-path  doc-type
        icon:          Contents/Resources/document.icns
        bindings:      .txt, .text, 'TEXT', text/plain
--
        name:          Plain text document
        rank:          Alternate
        roles:         Viewer
        flags:         apple-internal  relative-icon-path  doc-type  resolves-icloud-conflicts
        icon:          Contents/Resources/txt.icns
        bindings:      .txt, .text, 'TEXT', text/plain


Above we can see that the icon for the default is this: Contents/Resources/document.icns.

References


Where does Mac OS X store file association information?
defaults CLI
Launch Services Concepts