Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Protocol Handler not passing argument on OSX

I'm trying to hook up a custom protocol handler to my application on OSX so that I can do test://argument

In my plist I have the following:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
        <key>CFBundleURLIconFile</key>
        <string></string>
        <key>CFBundleURLName</key>
        <string>test</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>test</string>
        </array>
    </dict>
</array>

This successfully launches the application, however my argument list is always empty. Why is this?

Under the covers it launches a Java\Scala application, the main method is: object LoadJS { def main(args: Array[String]) {

I can pass in arguments when using the "open" command on the command line. Tried from both Chrome and Firefox but either work.

Any ideas?

Thanks

Ben

like image 724
Ben Hall Avatar asked Nov 03 '25 21:11

Ben Hall


1 Answers

The URL is not passed as argument. Rather, your app is started and then receives an AppleEvent of class kInternetEventClass and ID kAEGetURL. Maybe this post, which describes how to use your own protocol from Objective C, can help understand how it works:

How do you set your Cocoa application as the default web browser?

In order to actually handle this event from Java/Scala, you'll need to research some more and maybe write native code… Look at Apple's ApplicationAdapter class, which allows you to handle a few basic AppleEvents like open, reopen, about, etc.; but not the URL-related events, unfortunately. On this forum, someone reports doing it with JNI.

like image 54
Jean-Philippe Pellet Avatar answered Nov 06 '25 15:11

Jean-Philippe Pellet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!