94

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?

8 Answers 8

84

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.

17
  • 52
    4 minutes 19 seconds? Seriously?
    – Daniel Beck
    Feb 7, 2013 at 21:00
  • 2
    Thanks for the fast and detailed answer. Looks good! Question though - I think that I tried RCDefaultApp before and had some issue with it. Has it been working seamlessly for you?
    – cwd
    Feb 7, 2013 at 21:06
  • 2
    @nute Just from the top of my head, not sure. Perhaps an app created with Automator that wraps a shell script?
    – slhck
    Aug 25, 2015 at 11:17
  • 2
    The preference pane SwiftDefaultApps worked successfully for me on macOS 10.15.7 Catalina. I opened the preference pane, selected "URI schemes", scrolled down to the "tel" protocol handler, and changed it from Skype.app to FaceTime.app (Apple's native solution). And from then on selecting a telephone number in Safari and then right-clicking to open a context menu shows "Call XXX using iPhone" which then uses the native call handling instead of Skype again.
    – porg
    Dec 1, 2020 at 12:16
  • 2
    ^ Anyone interested, I created a full HowTo with screenshots at discussions.apple.com/thread/252116843
    – porg
    Dec 1, 2020 at 12:59
22

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

defaults read com.apple.LaunchServices/com.apple.launchservices.secure
2
  • 1
    Yay for using the builtin tools that don't break or require you to go download something.
    – xdhmoore
    Jan 12, 2018 at 1:18
  • 1
    This doesn't list all defaults for every protocol though, only some. Sep 29, 2019 at 7:05
22

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
6
  • 2
    I found a possible replacement for RCDefaultApp at github.com/Lord-Kamina/SwiftDefaultApps although you will have to build it yourself with Xcode.
    – luckman212
    Sep 1, 2017 at 13:16
  • I'm using version 2.1 of RCDefaultApp and it works just fine for me on 10.12. At least is still lists all items. Or does only some specific operation not work any more? Please elaborate Nov 28, 2017 at 14:58
  • @SuperTempel The lstool command-line tool displays this error when you try to run it: objc[1049]: Objective-C garbage collection is no longer supported. (lstool is the internal program used by the RCDefaultApp preference pane. While the preference pane appears to work, I don't think it can do anything because lstool is broken.) Dec 25, 2017 at 9:59
  • SwiftDefaultApps apparently doesn't work on Intel processors. No fix until at least April 2018. Mar 26, 2018 at 7:56
  • 4
    I am the developer of SwiftDefaultApps, SWDA was coded from the beginning with macOS Sierra and higher in mind (In fact, I began working on it after much frustration reading this question and similar ones). It was not working in 10.13 largely due to a bug in either Swift or macOS itself, but it appears to have been fixed with the update to 10.13.4/Swift 4.1. Apr 15, 2018 at 19:53
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 :-)

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).

2
  • Very nice idea, but I’m afraid I can’t get the supplied example script to work. More on your blog, awaiting moderation: getitdoneapps.wordpress.com/lincastor-browser/support/… Feb 17, 2017 at 21:15
  • That seemed to be some baffling line-break weirdness in the example file, diagnosed by running the script from the command line. (“/bin/sh: bad interpreter: Operation not permitted”) Saving a copy in BBEdit, and changing and recharging the line breaks to/from Windows, worked around the problem. Feb 25, 2017 at 18:58
4

You can also use duti:

echo $'com.apple.mail mailto\ncom.googlecode.iterm2 x-man-page'>~/.duti;duti ~/.duti
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.

1
  • 1
    What is this? Your answer is unclear. Aug 25, 2018 at 20:23

You must log in to answer this question.

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