Urgent! - Registering a URL Handler for a RunRev Application

Ben Rubinstein benr_mc at cogapp.com
Tue Jan 27 09:48:33 EST 2009


Dave wrote:
> This is a Mac only question!
> 
> Is it possible to register a URL Hander for an Application built using 
> RunRev?
> 
> Please see:
> 
> http://www.cocoadev.com/index.pl?HowToRegisterURLHandler
> 
> Which describes (sort of) how to do it for a regular Cocoa Application.
> 
> Some specific questions are:
> 
> Will this work in the IDE?
> 
> On a Standalone, how would I get the URL string in order to find out 
> what to do?

I'm not sure if I've understood you correctly (or how this relates to your 
polling issue) but FWIW: I do have an app which is set up to handle a custom 
protocol URL.

The app related to an extranet; by setting it up to handle a custom protocol, 
we were able to add links in the standard HTML pages which (if the user was 
appropriately set up) launched the app and made it do various things as 
appropriate.

Note that these weren't "real" URLs: the custom protocal at the front of the 
URL was sufficient to make the browser hand the whole URL off to our app, and 
the app then parsed the string to figure what it was supposed to do.

Anyway, if that is what you're after, the code looks like this (our custom 
protocol was "cdz", ie URLs were things like "cdz://resetresource/AIC01"):

    on appleEvent c, i, s
      if (i = "odoc") or (i = "codo") then -- note catch for intel Macs
        request appleEvent data
        handleAppleEvent c, i, s, it
      else if (c = "GURL") and (i = "GURL") then
        request appleEvent data
        handleAppleEvent c, i, s, it
      else if (c = "core") and (i = "save") then
        -- simple handling for now
       ...
      else
        pass appleEvent
      end if
    end appleEvent

    on handleAppleEvent tClass, tID, tSender, tData
      switch tClass && tID
      case "aevt odoc"
      case "tvea codo" -- intel Macs
        ... do stuff to open a file: tData is path to file
        break
      case "GURL GURL"
      case "LRUG LRUG" -- intel Macs
        -- do stuff to handle the request, tData is the URL, including protocol
         if char 1 to 4 of tData = "cdz:" then
            processCDZgurl char 6 to -1 of tData -- strip leading "cdz://"
         else
            dbgReport ("Unknown protocol in GURL event:" && tData)
          end if
          break
      end switch
    end handleAppleEvent

(NB checking for reversed four character codes was necessary when the first 
intel Macs came in, and I was still building PPC apps which ran under Rosetta; 
I've never bothered to find out whether this was an Apple or Rev issue, and 
whether it's fixed with current versions.  So it might be redundant now.)

This does work in the IDE, so long as the "on appleEvent" handler is in the 
message path when the call arrives (eg your stack is top-level, or you've put 
it in the backscripts).  However, you'll have to set Revolution to be the 
protocol handler when you're working in the IDE, and then set it back to your 
app when you want the standalone to work - obviously, the operating system has 
just one view at any time as to what app should handle a particular protocol, 
it doesn't broadcast the request to all possible apps.

(I use a third party control panel "More Internet" to control this mapping; 
there are many others eg TinkerTool - for some reason Apple no longer include 
a GUI for modifying this directly.  Evidently not something users are supposed 
to worry their pretty little heads about...)

HTH,

- Ben






More information about the use-livecode mailing list