Skip to content

Find Any File

Find Any File 是一款 macOS 文件搜索应用。Protocol Launcher 可以生成 Find Any File URL scheme 链接。

使用

有两种方式可以使用此库:

  • 按需从子路径导入,支持 Tree Shaking 并保持包体积较小。
  • 从根包完整导入更适合快速脚本或示例,但会包含全部应用模块。

生产构建建议使用按需导入;快速演示可以使用完整导入。

选择安装方式

按需加载
推荐使用。生产环境优化。
全量导入
使用便捷。适合快速脚本。

说明

Find Any File 官方 URL scheme 文档定义了用于查询参数搜索的 fafapp://find?...,以及用于 JSON 搜索规则的 fafapp://findjson/jsondatafafapp://findjson/jsondata/wmode。此模块只暴露这些已文档化的形式。

find()findInLocation()findWithTemplate() 中,payload 使用 FAF 官方文档里的参数名:inplocwinrootrunnoruntpl。字符串 inp 会序列化为 inp;数组会序列化为 inp1inp2 等。字符串 loc 会序列化为 loc;数组会序列化为 loc1loc2 等。

查找

打开 Find Any File,并填入第一个输入框进行搜索。

On-Demand
ts
import { find } from 'protocol-launcher/find-any-file'

const url = find({
  inp: 'invoice',
})

在指定位置查找

在指定 Find Any File 位置中搜索,例如 ~、POSIX 路径、file URL、HFS 路径,或 FAF 文档列出的特殊 # 位置。

On-Demand
ts
import { findInLocation } from 'protocol-launcher/find-any-file'

const url = findInLocation({
  loc: '~',
  inp: 'invoice',
})

使用模板查找

使用保存的 Search Template 名称,不包含 .faf 扩展名。

On-Demand
ts
import { findWithTemplate } from 'protocol-launcher/find-any-file'

const url = findWithTemplate({
  tpl: 'LastWeek',
  inp: 'invoice',
})

JSON 查找

使用从 Find Any File 已保存搜索中复制出的 JSON 搜索规则。当 jsondata 是对象时,字符串值会进行百分号编码,JSON 标点会保留为 FAF 官方示例中的形式。当 jsondata 是字符串时,会原样使用。wmode 会追加官方文档中的可选窗口模式 path 片段。

On-Demand
ts
import { findJson } from 'protocol-launcher/find-any-file'

const url = findJson({
  jsondata: {
    specs: [{ verb: 9, val: 'report 2021', subj: 0 }],
    title: 'Name contains report 2021',
    autoStart: true,
    sources: ['/'],
  },
})

生成的 URL

ts
find({ inp: 'invoice' })
// => 'fafapp://find?inp=invoice'

findInLocation({
  loc: '~',
  inp: 'invoice',
})
// => 'fafapp://find?inp=invoice&loc=~'

findWithTemplate({
  tpl: 'LastWeek',
  inp: 'invoice',
})
// => 'fafapp://find?inp=invoice&tpl=LastWeek'

findJson({
  jsondata: {
    specs: [{ verb: 9, val: 'report 2021', subj: 0 }],
    title: 'Name contains report 2021',
    autoStart: true,
    sources: ['/'],
  },
})
// => 'fafapp://findjson/{"specs":[{"verb":9,"val":"report%202021","subj":0}],"title":"Name%20contains%20report%202021","autoStart":true,"sources":["%2F"]}'

官方文档