Spotlight PRO

Spotlight 允许脚本把自己的资源加入系统 Spotlight 索引。用户点击其中一条搜索结果后,Scripting 会运行同一脚本项目里的 spotlight.tsx 文件。

Spotlight 索引功能需要 Scripting PRO。

添加索引

await Spotlight.index({
  id: "note-42",
  title: "Project Notes",
  subtitle: "Pinned note",
  description: "Open the project note from Spotlight.",
  keywords: ["notes", "project"],
  parameters: {
    noteID: "42",
    source: "spotlight"
  }
})

id 只需要在当前脚本内唯一。再次使用相同 id 调用 Spotlight.index 会更新已有条目。

await Spotlight.indexItems([
  {
    id: "task-1",
    title: "Follow up"
  },
  {
    id: "task-2",
    title: "Send invoice",
    parameters: { invoiceID: "2026-001" }
  }
])

处理点击

在脚本项目里创建 spotlight.tsx

const item = Spotlight.current

if (item) {
  console.log(item.id)
  console.log(JSON.stringify(item.parameters))
}

Spotlight.current 在其他运行环境中为 null。当 spotlight.tsx 是由 Spotlight 搜索结果启动时,它一定包含当前点击条目的上下文。

Spotlight 点击参数不会写入 Script.queryParameters

管理条目

const items = await Spotlight.getItems()

await Spotlight.delete("note-42")
await Spotlight.deleteItems(["task-1", "task-2"])
await Spotlight.deleteAll()

用户也可以在 Tools > Spotlight 中管理已索引条目,包括删除脚本或 spotlight.tsx 文件已经不存在的记录。