title: How to use custom URL scheme to send Get URL event to running application?
body: <p>My Cocoa application needs to handle Get URL events. I think I correctly followed the steps in <a href="https://stackoverflow.com/questions/49510/how-do-you-set-your-cocoa-application-as-the-default-web-browser">this answer</a> to modify Info.plist and write &amp; register a URL handler method. </p>
  
  <p>Problems: </p>
  
  <ol>
  <li><p>When I go mytesturl://anything in Safari while my app is running, it pops up a window asking if I want to open my app. And if I say yes, nothing seems to happen except that an icon appears for an instant in the dock. So it might be trying to launch another instance of my app instead of sending a message to the running instance? </p></li>
  <li><p>When I do the same in Firefox, it pops up a window asking me to choose an application. So custom URL protocols are not expected to work in all browsers? </p></li>
  </ol>
  
  <p>Info.plist: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
  &lt;plist version="1.0"&gt;
  &lt;dict&gt;
      ...
      &lt;key&gt;CFBundleURLTypes&lt;/key&gt;
      &lt;array&gt;
          &lt;dict&gt;
              &lt;key&gt;CFBundleURLName&lt;/key&gt;
              &lt;string&gt;My test URL&lt;/string&gt;
              &lt;key&gt;CFBundleURLSchemes&lt;/key&gt;
              &lt;array&gt;
                  &lt;string&gt;mytesturl&lt;/string&gt;
              &lt;/array&gt;
          &lt;/dict&gt;
      &lt;/array&gt;
       ...
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  
  <p>Source code: </p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  #include &lt;stdio.h&gt;
  
  @interface Test : NSObject
  {
  }
  - (void)test;
  - (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; 
  @end
  
  @implementation Test
  - (void)test
  {
      NSLog(@"Started..."); 
      char c; 
      scanf("%c", &amp;c); 
  }
  
  - (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
  {
      NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
      NSLog(@"url = %@", url); 
  }
  @end
  
  int main(int argc, char *argv[])
  {
      Test *app=[[Test alloc] init];
      [[NSAppleEventManager sharedAppleEventManager] setEventHandler:app andSelector:@selector(handleEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
  
      [app test];
  
      return 0;   
  }
  </code></pre>