面向开发者

Switchbar API

Switchbar 提供基于 URL 的 API。只需打开一个特定格式的 URL,Switchbar 就会立即开始工作——将链接发送到正确的浏览器或邮件客户端,或提示你选择一个。

工作原理

switchbar://open/<link>
  • 网页和邮件链接

    可传入任何 https://、http:// 或 mailto: 链接。

  • 遵循你的规则

    链接会像点击一样经过你的规则和链接设置。如果没有匹配的规则,Switchbar 会询问在哪里打开。

  • 无需编码

    在 switchbar://open/ 后直接附上链接,无需进行百分号编码。

示例

Terminal

# macOS
open "switchbar://open/https://example.com"
open "switchbar://open/mailto:hello@example.com"

# Windows
start "" "switchbar://open/https://example.com"

AppleScript

open location "switchbar://open/https://example.com"

JavaScript

window.location.href = "switchbar://open/https://example.com";

Swift

let url = URL(string: "switchbar://open/https://example.com")!
NSWorkspace.shared.open(url)

兼容 Choosy URL

Switchbar 也能打开 Choosy API 链接,为 Choosy 编写的脚本和工具无需修改即可使用。

x-choosy://open/
x-choosy://prompt.all/
x-choosy://prompt.running/
x-choosy://best.all/
x-choosy://best.running/