4

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

2
  • Care to upvote/accept an answer or tell us more about what kind of explanations you want? Commented Apr 18, 2011 at 19:52
  • No need to write native code for recent Java versions. For Java 9 you can use the following, stackoverflow.com/questions/27435606/…. Commented Oct 16, 2018 at 16:15

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.