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

前端 未结 6 886
情书的邮戳
情书的邮戳 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:21

    As of today, the best way I found to solve this problem on a Mac with the least overhead is using the command line duti which allows me to define in a very simple text file all my associations:

    brew install duti

    You will need two things. First bundle ids of the Apps you want to associate:

    mdls -name kMDItemCFBundleIdentifier /Applications/MacVim.app

    Second the UTI of the file type, Apple provides a list, but you can also explore the supported UTI by your app like this:

    mdls -name kMDItemContentTypeTree /Applications/MacVim.app

    Now make a text file somewhere in your system where you associate bundle ids with UTI:

    # ~/.default-apps.duti
    #
    # bundle id       UTI                  role
    com.apple.Safari  public.html          all
    org.vim.MacVim    txmt
    org.vim.MacVim    public.ruby-script
    

    Notice that I can associate a URL handler like txmt and also file types like Ruby scripts.

    In that file you I keep track of all my app preferences and reproduce them immediately after a complete fresh install or when getting an account on other Mac just running:

    duti ~/.default-apps.duti
    

提交回复
热议问题