defaultapp
In this tweet yesterday, John Gruber of Daring Fireball fame asked:
Anyone have a shell or AppleScript command that tells you what the current default web browser is?I had written code to do this for my upcoming app, so i spent a few minutes packaging it up as a command line tool. I present to you defaultapp. Download it here. The zip file contains the now public domain source (not too pretty) and the "defaultapp" executable. To use it, give it a -n, -b, -p or -a and a document extension. The options (in order) yield the app's name, bundle id, path or all three. Thus:
$ ./defaultapp -n html Safari.app $ ./defaultapp -b html com.apple.Safari $ ./defaultapp -p html /Applications/Safari.app $ ./defaultapp -a html Safari.app /Applications/Safari.app com.apple.SafariThe tool uses LaunchServices to determine url of default app for the given document extension and then LaunchServices again to find the application name. The bundle id is determined via the carbon CFBundleCopyInfoDictionaryInDirectory call. You can probably do this with Cocoa, but i found the carbon call to be more reliable. YMMV.
