Switchbar API


Switchbar 提供基于 URL 的 API,可根据你配置的规则在浏览器和电子邮件客户端中打开链接。

URL 格式

switchbar://open/<link>

支持的链接类型:

  • https://
  • http://
  • mailto:

直接在后面附加链接,无需进行百分号编码。

Switchbar 会应用你现有的规则和链接设置。如果没有匹配的规则,它会提示你选择打开链接的应用。

示例

终端

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 兼容性

Switchbar 还支持 Choosy URL 方案,让现有脚本和集成无需修改即可使用。

支持的 URL 前缀:

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

将目标链接附加到相应前缀后面。