How to map a custom protocol to an application on the Mac?

前端 未结 6 887
情书的邮戳
情书的邮戳 2020-11-27 02:58

I\'m trying to register a custom protocol to an application on the Mac, i.e:

  1. User clicks on link with \"abcdef://some/url/here\"
  2. An installed applicat
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-27 03:30

    On Macs this is easy to do with AppleScript. The most detailed description is in this article, Launch Scripts from Webpage Links on Mac. I'd read that page since it includes a full walk-through and a full working example to download.

    Basically, you make an event handler in a script:

    on open location this_URL
        display dialog "I'm doing something with this URL: " & return & this_URL
    end open location
    

    Then save that as an Application. Then in the Finder use Show Package Contents to edit the Info.plist. You add some properties to the app to register it as a handler for your protocol.

    CFBundleURLTypes
    
        
            CFBundleURLName
            Cliff's handler
            CFBundleURLSchemes
            
                abcdef
            
        
    
    

提交回复
热议问题