98

I've been reading a lot online about custom URL handlers / custom protocol handlers such as:

I get that you can tell the system that a particular program is able to handle a certain scheme / protocol with the Info.plist file:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>Local File</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>local</string>
        </array>
    </dict>
</array>
<key>NSUIElement</key>
<true/>

But if there are multiple applications that are capable of opening the same URL handler, such as mailto: how do you specify which one you want the system to use?

There were some references to utilities like the More Internet preference pane which no longer seems to be available from the author's site. I did find it online by Googling but it seems a bit shaky - like it was written for an older OSX - perhaps Tiger.

I haven't been able to find information on how to set the URL handler for protocols and custom protocols. I'm assuming there is a plist file somewhere that I can edit - or maybe there is a newer, better utility that works well with Mountain Lion?

cwd
  • 18,788
  • 43
  • 123
  • 162

8 Answers8

87

The file you seek is ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist.

It holds an array called LSHandlers, and the Dictionary children that define an LSHandlerURLScheme can be modified accordingly with the LSHandlerRole. You need to [convert this binary file][1] to edit it.

Rather than manually editing this file, you can use SwiftDefaultApps. Note that this app is a successor to RCDefaultApp, which has been unmaintained, but it also appears to have some bugs.

slhck
  • 235,242
25

Listing current LaunchServices URL handler settings on Apple OS X 10.10 (Yosemite):

defaults read com.apple.LaunchServices/com.apple.launchservices.secure
23

Update Jul 2017: RCDefaultApp and lstool no longer work on macOS 10.12 or later. We'll have to find a new solution.

Edit Mar 2018
I found SwiftDefaultApps but can't test as I'm not on High Sierra yet.


Furthering the previous answer, if you would like to do this on the command line you can use the lstool command, which is the core of RCDefaultApp, found under RCDefaultApp.prefPane/Contents/Resources/lstool.

Its usage is straightforward:

[~]$lstool --help
Usage:

lstool read [<lsscheme> [<type>]]
lstool [-n] write <lsscheme> <type> <app>
lstool [-n] setoption <lsscheme> <type> login|ignorecreator YES|NO
lstool [-n] register {<app>}
lstool [-n] unregister {<path> | <app>}
lstool apps

-n means do not make changes
<lsscheme> is one of: internet, media, url, extension, uti, mime, ostype
<app> is the path to an application or a name to be looked up
Tetsujin
  • 50,917
9

Open the file with XCode works quite easy.

Using the build in command plutil as described in the answer on https://discussions.apple.com/thread/5815759 to convert between format xml1 or binary1 works similar.

plutil -convert xml1 /file-i-wish

nano /file-i-wish & save file 

plutil -convert binary1 /file-i-wish

No need for 'alien' tools :-)

techraf
  • 4,952
Clemens Tolboom
  • 190
  • 1
  • 4
5

I actually wrote an application simplifying registration of custom URL protocols, if anyone is interested. It is called LinCastor (https://onflapp.github.io/blog/pages/LinCastor.html). Handlers can be defined as AppleScript or shell script (which can perl, python or what ever).

keen
  • 143
4

You can also use duti:

echo $'com.apple.mail mailto\ncom.googlecode.iterm2 x-man-page'>~/.duti;duti ~/.duti
keen
  • 143
Lri
  • 42,502
  • 8
  • 126
  • 159
1

Another way to list current LaunchServices URL handler settings with Xcode on Apple OS X 10.10+ (Yosemite):

open -a Xcode ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
-1

I just tried the old More Internet, under El Capitan.

It is funky and the only way it works is via using the up and down arrow keys to select the protocol, and a drag/drop of the APP icon into the window to make a change.

I switched the default from Safari to Chrome, and the change stuck, so it works still.