This will tell you how to have browsers run command line commands when visiting urls with custom schemes custom://
.
- Tell the browser how to handle the url scheme
- Tell the OS how to handle the url scheme
- Parse the url
- Run your command
Using javascript.
window.navigator.registerProtocolHandler(protocol, uri, title);
The protocol
must be prefixed with web+
since it's not a whitelisted URL Scheme.
navigator.registerProtocolHandler('web+apm', 'apm://%s', 'Atom Package Manager');
http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx
Windows requires an empty URL Protocol
key to flag that your entry is a URL Scheme handler.
First make a new key at HKEY_CLASSES_ROOT\custom
where custom
is your url scheme.
Second make a new key at HKEY_CLASSES_ROOT\custom\shell\open\command
, and set the default value to your command. Use the %1
variable to pass the entire url to your command.
REGEDIT4
[HKEY_CLASSES_ROOT\echo]
@="URL:Echo In CMD Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\echo\shell\open\command]
@="cmd /k echo %1"
https://github.com/Zren/atom-misc/blob/master/assets/RegisterApmUrlScheme.reg
REGEDIT4
[HKEY_CLASSES_ROOT\apm]
@="URL:Atom Package Manager Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\apm\shell\open\command]
@="\"C:\\Program Files\\nodejs\\node.exe\" \"C:\\Users\\Admin\\.atom\\packages\\misc\\bin\\apmUriHandler.js\" \"%1\""
Remember that you are passed the entire url, and that it might not have the //
. An example is the mailto
scheme. Eg: mailto:admin@example.com
.
NodeJS isn't the best tool to script in, but here's an example.
https://github.com/Zren/atom-misc/blob/master/bin/apmUriHandler.js
The last step should have parsed the url, but unless it's executing your task, it's probably just the glue that launches your actual command with properly formatted parameters.
- Steam (
steam://
)
https://developer.valvesoftware.com/wiki/Steam_browser_protocol