开发者

Using a Spotlight search result to open an application in a specific state

开发者 https://www.devze.com 2023-01-21 13:47 出处:网络
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 item

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 d开发者_JAVA技巧ropdown 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消