Get the default application from launch services

I’ve seen people wanting to get a user’s default web browser or their default application for another file. I recently need this too. I wrote a command line tool to do this. You can pass in a file extension or the path to a file to the tool and it will return the path to the application that will launch it.

You can get the tool from my website here.

So for example, if you wanted a user’s default web browser you could do this…

set daPath to (path to home folder as text) & "UnixBins:DefaultApplication"
set theExtension to "html"

do shell script quoted form of POSIX path of daPath & " -ext " & quoted form of theExtension

The application has been updated to version 0.2. It now works with url’s too and works on computers with Mac OS X 10.1 or later. So now if I wanted a user’s default email application I could do this…

set daPath to (path to home folder as text) & "UnixBins:DefaultApplication"
set theURL to "mailto:"

do shell script quoted form of POSIX path of daPath & " -url " & quoted form of theURL