# API & PopClip 插件

![](https://1003988539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl32LfsaljX9FHbl3ksjH%2Fuploads%2FY0Doxu3S8xo0gGiK1mZW%2FPopClip%20%E6%8F%92%E4%BB%B6.png?alt=media\&token=c433d64f-6609-47d9-ade8-b812563a9c0b)

最新版本的 HapiGo 已支持通过 URL Scheme 及 AppleScript 2 种方式来调用 HapiGo。通过这些 API，你可以将其他应用的文本发送到 HapiGo 进行搜索或翻译。如果你是 PopClip 用户，我们也开发了 PopClip 插件，方便你更便捷的操作文本。

### URL Scheme

```url
hapigo://open?extensionID={id}&query={query}
```

其中 query 为关键词变量，extensionID 为扩展的 id。extensionID 部分目前仅开放 4 个内置扩展，后续计划支持全部扩展。4 个内置扩展 id 如下：

* **APP**：发送文本至 HapiGo 应用搜索
* **FILE**：发送文本至 HapiGo 文件搜索
* **CLIPBOARD**：发送文本至 HapiGo 剪贴板搜索
* **TRANSLATE**：发送文本至 HapiGo 翻译

{% hint style="info" %}
当 HapiGo 搜索模式为「混合搜索」时，APP 和 FILE 的效果相同，均为发送文本至主搜索。
{% endhint %}

**URL Scheme 示例**

```css
#在应用模式中搜索「hapigo」：
hapigo://open?extensionID=APP&query=hapigo

#在文件模式中搜索「pdf」：
hapigo://open?extensionID=FILE&query=pdf

#在剪贴板中搜索「request」：
hapigo://open?extensionID=CLIPBOARD&query=request

#在 HapiGo 中翻译「app」：
hapigo://open?extensionID=TRANSLATE&query=app
```

### AppleScript

作为原生应用，HapiGo 也支持使用 AppleScript 调用 HapiGo。打开 AppleScript 脚本编辑器，点击菜单栏「文件」-「打开词典」可以找到 HapiGo 的 AppleScript 语法词典。

![](https://1003988539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl32LfsaljX9FHbl3ksjH%2Fuploads%2FkuY87ItfrU0ISWpvNwdI%2F%E6%88%AA%E5%B1%8F2022-08-03%2017.03.55.png?alt=media\&token=83bf4a50-5d7c-4ef5-81b9-f82d01bfc7b5)

与 URL Scheme 所提供的功能一样，AppleScript 可以在 HapiGo 中搜索应用、文件、剪贴板及进行翻译。

**AppleScript 示例**

```applescript
#在应用模式中搜索「hapigo」：
tell application "HapiGo"
    search app "hapigo"
end tell

#在文件模式中搜索「pdf」：
tell application "HapiGo"
    search file "pdf"
end tell

#在剪贴板中搜索「request」：
tell application "HapiGo"
    search clipboard "request"
end tell

#在 HapiGo 中翻译「app」：
tell application "HapiGo"
    translate "app"
end tell
```

### Popclip 插件

除了提供 URL Scheme 及 AppleScript 接口，我们也开发了现成的 PopClip 插件供大家使用。下载插件后双击安装。此时会在菜单栏 PopClip 图标处弹出 4 个功能选择，分别为：HapiGo 应用搜索、HapiGo 文件搜索、HapiGo 翻译、HapiGo 剪贴板搜索，大家可以根据需要进行选择。后续如需调整，也可以在 PopClip 的插件列表中找到 HapiGo，然后点击后面的齿轮进行设置。

插件的标签描述提供 3 种语言：简体中文、繁体中文、英文。

下载链接：<https://dl.hapigo.com/HapiGoPopClipPlugin.zip>

![](https://1003988539-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl32LfsaljX9FHbl3ksjH%2Fuploads%2FFY2ayLZYGu8rEYgaXyVB%2FPopClip%20%E8%AE%BE%E7%BD%AE.png?alt=media\&token=8b5da571-915f-48bb-8000-55e8328f0659)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs-cn.hapigo.com/adv/urlscheme.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
