使用 Spotlight 搜索结果打开特定状态的应用程序

发布于 2024-09-28 19:50:48 字数 174 浏览 5 评论 0原文

我有一个应用程序,可以通过从下拉菜单中选择来播放一系列广播电台。理想情况下,我想添加一些代码,以便聚光灯搜索返回下拉列表中的任何项目并打开应用程序,就像您在应用程序本身中执行此操作一样。

除了我发现的一些关于创建要索引的隐藏文件的旧帖子之外,聚光灯文档没有提供任何关于这是否可能的线索。

有什么线索吗?

I have an application that will play a series of radio stations by choosing them from a drop down menu. Ideally I'd like to add some code, so that a spotlight search that would return any of the items in the dropdown and open the application as if you did this from within the application itself.

The spotlight documentation gives no clues to whether this is possible, apart from some old posts I found about creating hidden files to be indexed.

Any clues?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰魂雪魄 2024-10-05 19:50:48

您的各个电台在内部如何存储/表示? Spotlight 是一个文件一个搜索结果。具有单个库数据库或类似库的应用程序通常将这些项目导出到 ~/Library/Caches 文件夹的子文件夹中。您可以为每个要搜索的项目编写一个聚光灯“存根”文件。这个“存根”文件将有自己单独的扩展名/文档类型(仍然可以由您的应用程序打开),这就是您的 Spotlight 导入器的基础。

先例:AddressBook.app。

例如,在我的一个应用程序中,有一个中央(非基于文档的)转录库数据库。我希望用户能够搜索单个文本并将它们作为单独的结果显示在 Spotlight 中。解决这个问题的唯一方法是我的应用程序创建并维护一个一次性的“.transcriptstub”文件集合,其中包含可搜索的文本表示形式。

我说“一次性”是因为 ../Caches 中的内容在丢失时可以很容易地由您的应用程序重新创建。如果需要,我会在应用程序启动时更新它们(作为单独的 NSOperation 以防止长时间启动),并且每个单独的更新都会在运行时进行修改。

当应用程序收到要打开的这些存根之一时,它会使用文件中的某些标识符(也许是 UUID?)并在数据库中查找该标识符。如果存在匹配项,则会在 UI 中选择该项目。

How are your individual stations stored / represented internally? Spotlight is one-file-one-search-result. Apps with a single library DB or similar traditionally export those items in a subfolder of the ~/Library/Caches folder. You'd write one spotlight "stub" file per item you want to be searchable. This "stub" file will have its own separate extension/doctype (that's still openable by your app) and that's what you'll base your Spotlight importer on.

Precedent: AddressBook.app.

For example, in one of my apps, there's a central (non-document-based) transcript library database. I wanted users to be able to search individual transcripts and have them show up as separate results in Spotlight. The only way around this was for my application to create and maintain a disposable collection of ".transcriptstub" files that held a searchable text representation.

I say "disposable" because things in ../Caches are meant to be easily recreated by your application if missing. I update them if needed at application launch (as a separate NSOperation so as to prevent long launches), and each individual one as it's modified during runtime.

When the application is handed one of these stubs to open, it uses some identifier in the file (a UUID perhaps?) and looks for that in the database. If there's a match, it selects that item in the UI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文