26

Alfred - Script Filter

 5 years ago
source link: http://saitjr.com/others/alfred-script-filter-json-format.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Alfred 3 推荐 JSON 作为 Script Filter 返回的格式。这样以来,用 Alfred 写 Workflow 就更加方便,更加通用。所以翻译了一下官方文档…

环境信息

Alfred 3.8.1

第一步…最后一步

差不多只需要一步,就能知道 Script Filter 是什么。Alfred -> Workflows -> + -> Getting Started -> Script Filter。创建以后,能看到 jsonformatxmlformat 模板。在 Alfred 中,输入 jsonformat ,能看到效果:

YZFnU3J.jpg!web

双击 jsonformat ,能看到这个 Script Filter 返回了一个 items 数组。数组有四个元素,就对应着 Alfred 显示的四个 item。所以规则也就显而易见了。

规则

Script Filter 要求返回 items 数组,每个 item 就是 Alfred 显示的行。

{"items": [
    {
        "uid": "desktop",
        "type": "file",
        "title": "Desktop",
        "subtitle": "~/Desktop",
        "arg": "~/Desktop",
        "autocomplete": "Desktop",
        "icon": {
            "type": "fileicon",
            "path": "~/Desktop"
        }
    }
]}

属性

上面看到的实例只是其中一部分属性,接下来一一说明下。

uid : String(可选)

每个 item 的唯一标识,后续 Alfred 能依托这个 uid,根据用户操作进行排序。如果想保持自己脚本返回的顺序,不用 Alfred 的排序,可以不设置这个字段。

"uid" : "xxx-xxx-xxx"

title

顾名思义,Row 的标题。

"title" : "Desktop"

subtitle(可选)

副标题

"subtitle" : "~/Desktop"

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK