開発者向け

Switchbar API

Switchbar には URL ベースの API があります。特別な形式の URL を開くと、Switchbar が動作し、リンクを適切なブラウザやメールクライアントに送るか、どれを使うか選ぶよう促します。

仕組み

switchbar://open/<link>
  • Webリンクとメールリンク

    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/