How to register a url protocol handler in Node.js

前端 未结 3 367
醉梦人生
醉梦人生 2020-12-23 17:22

I am developing a command line node module and would like to be able to launch it via links on a website.

I want to register a custom protocol my-module://

3条回答
  •  失恋的感觉
    2020-12-23 18:04

    Here's how I did on Mac OS with an application NW.js :

    1. Open the app /Applications/Utilities/Script Editor

      type the following code in the editor

      on open location this_URL
         do shell script "/Applications/X.app/Contents/MacOS/x '" & this_URL & "'"
      end open location
      

      Replace X by the name of your App.

      Save the script as an Application Bundle anywhere

    2. Go to the script, right click then 'Show Package Contents' then edit Contents/info.plist

      Add these lines at the end of the file, just before :

      CFBundleIdentifier
      com.mycompany.AppleScript.AppName 
      CFBundleURLTypes
      
        
          CFBundleURLName
          AppName 
          CFBundleURLSchemes
          
            myurlscheme 
          
        
      
      
    3. You can now open a link starting with myurlscheme: and see your app is opening!

提交回复
热议问题