定制URL方案的MacOS机制

MacOS mechanism for customized URL scheme

我正在尝试了解自定义 URL 方案在 Mac 中的工作原理,如此处所述:https://css-tricks.com/create-url-scheme/

例如,当单击 mailto:link 时,用户会看到“邮件”应用程序启动,并弹出一个作曲家 window,其中已经填写了正确的收件人地址。

我很确定在 Windows 中,您可以在调用处理应用程序时将与您的协议相关的字符串(例如,包括接收方地址等)作为命令行参数传递。也就是说,您有机会在处理应用程序启动时解析命令行。

但是MacOS好像不是这样?在上面的例子中,它是否首先调用 'Mail',然后 'Mail' 从其注册的回调中获取与协议相关的字符串(接收者的地址等)?也就是说,您只能在处理应用程序 已经启动 运行 时才能获取地址?

在 Mac 中,是否可以执行与 Windows 中相同的操作,在启动处理应用程序时传递命令行参数?

In the above example, does it invokes 'Mail' first, then 'Mail' gets the string related to the protocol (receiver’s address etc.) from its registered callback? i.e. you can only get the address when the handling application already started running?

正确。一旦应用程序启动——如果它还没有 运行——它会收到一个事件(通过 Apple Events!)通知它应该打开 URL.

In Mac, is it possible to do the same thing as in Windows, passing command line arguments when launching the handling application?

没有。通常,macOS 应用程序通常不使用命令行参数。在这种特定情况下,命令行参数无论如何都是不合适的,因为它们不能用于将信息传递给已经打开的应用程序。