How do I configure custom URL handlers on OS X?

67

36

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

Posted 2013-02-07T20:54:37.373

Reputation: 13 508

Answers

59

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.

Rather than manually editing this file, you can also use RCDefaultApp, which gives you a nice Preference Pane. It is said not to be working for macOS 10.12 and up, but I can confirm it runs under macOS 10.14.

An alternative is SwiftDefaultApps.

For example, here's SVN and SSH:

… and in RCDefaultApp:

slhck

Posted 2013-02-07T20:54:37.373

Reputation: 182 472

This seems to be to open a real "app". What if I want to do some custom processing, using a terminal command, etc? – nute – 2015-08-25T07:57:00.703

1@nute Just from the top of my head, not sure. Perhaps an app created with Automator that wraps a shell script? – slhck – 2015-08-25T11:17:42.950

How can I receive input in the automator? Like, the content of the URL? – nute – 2015-08-25T11:30:46.780

Just a note, if you have multiple apps/app-versions handling the same protocol (e.g. IntelliJ EAP, IntelliJ), you can choose the specific one to use in the the Apps tab in RCDefaultApp. It is still working for me in macOS 10.11. – vaughan – 2016-06-14T03:24:16.917

May need to revise the answer since the image 1st image is missing and the 2nd image code has been reassigned to a completely irrelevant image – MrU – 2016-07-29T02:22:25.740

@MrU Not sure what you're talking about – the post shows like this for me: http://imgur.com/a/4o7fZ

– slhck – 2016-07-29T07:49:37.900

@slhck Wierd... I'm recieving a 404 image, and an image related to the Akinator.... – Looking in the post's details here are the links that I'm getting. 404 – http://i.stack.imgur.com/HVCo2.png | Akinator – http://i.stack.imgur.com/S9xqn.png

– MrU – 2016-07-30T07:57:21.560

@MrU I suppose your ISP or another entity is messing with your Internet access? – slhck – 2016-07-31T09:20:03.913

364 minutes 19 seconds? Seriously? – Daniel Beck – 2013-02-07T21:00:15.487

2Thanks 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 – 2013-02-07T21:06:34.697

@cwd I honestly have to say I don't use it often. More for screenshots for Super User than anything else :) Whenever I need to change file associations I do it through the Get Info… dialog in Finder. I never needed to change protocol and MIME handlers. But it seemed stable enough for me. – slhck – 2013-02-07T21:09:43.107

15

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

Quinn Comendant

Posted 2013-02-07T20:54:37.373

Reputation: 771

2

I found a possible replacement for RCDefaultApp at https://github.com/Lord-Kamina/SwiftDefaultApps although you will have to build it yourself with Xcode.

– luckman212 – 2017-09-01T13:16:42.613

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 – SuperTempel – 2017-11-28T14:58:18.067

@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.) – Quinn Comendant – 2017-12-25T09:59:59.603

SwiftDefaultApps apparently doesn't work on Intel processors. No fix until at least April 2018.

– Quinn Comendant – 2018-03-26T07:56:56.100

3I 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. – Gregorio Litenstein – 2018-04-15T19:53:56.720

I tried running lstool in macOS 10.13, and I got: objc[14334]: Objective-C garbage collection is no longer supported.. – Alan Zhiliang Feng – 2018-06-04T21:00:38.197

12

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

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

VirtualJMills

Posted 2013-02-07T20:54:37.373

Reputation: 121

Yay for using the builtin tools that don't break or require you to go download something. – xdhmoore – 2018-01-12T01:18:36.970

This doesn't list all defaults for every protocol though, only some. – Vadim Peretokin – 2019-09-29T07:05:11.940

5

I actually wrote an application simplifying registration of custom URL protocols, if anyone is interested. It is called LinCastor (http://onflapp.wordpress.com/lincastor/). Handlers can be defined as AppleScript or shell script (which can perl, python or what ever).

On Flapp

Posted 2013-02-07T20:54:37.373

Reputation: 59

Very nice idea, but I’m afraid I can’t get the supplied example script to work. More on your blog, awaiting moderation: https://getitdoneapps.wordpress.com/lincastor-browser/support/comment-page-1/#comment-9

– Flash Sheridan – 2017-02-17T21:15:13.480

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. – Flash Sheridan – 2017-02-25T18:58:11.990

5

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

Clemens Tolboom

Posted 2013-02-07T20:54:37.373

Reputation: 150

4

You can also use duti:

echo $'com.apple.mail mailto\ncom.googlecode.iterm2 x-man-page'>~/.duti;duti ~/.duti

Lri

Posted 2013-02-07T20:54:37.373

Reputation: 34 501

0

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.

Calgary Guru

Posted 2013-02-07T20:54:37.373

Reputation: 1

What is this? Your answer is unclear. – lacostenycoder – 2018-08-25T20:23:18.950

0

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

oikonomopo

Posted 2013-02-07T20:54:37.373

Reputation: 105