如何使用 PyObjC 绑定和 NSMetadataQuery 编写与 mdfind 等效的 python 脚本?
我想写一个相当于 mdfind 的 python 程序。我想使用 .Spotlight-V100 元数据,但找不到所使用的元数据数据库格式的描述,但 NSMetadataQuery 似乎正是我所需要的。我想使用内置的 Obj-C 绑定在 python 中执行此操作,但无法找出正确的咒语以使其工作。不确定问题是否在于调用的异步性质,或者我只是错误地将事物连接在一起。
一个相当于“mdfind”的简单例子就可以作为开始。
I want to write the python equivalent of mdfind. I want to use the .Spotlight-V100 metadata and I cannot find a description for the metadata db format used, but NSMetadataQuery seems to be what I need. I'd like to do this in python using the built in Obj-C bindings, but have not been able to figure out the correct incantation to get it to work. Not sure if the problem is the asynchronous nature of the call or I'm just wiring things together incorrectly.
A simple example giving the equivalent of of "mdfind " would be fine for a start.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了一个非常简单的版本。我的谓词不太正确,因为等效的 mdfind 调用具有其他结果。此外,它需要两个参数,第一个是要使用的基本路径名,第二个是搜索词。
这是代码:
查询调用是异步的,因此为了更完整,我应该注册一个回调并让运行循环连续运行。事实上,我搜索了 5 秒,所以如果我们有一个需要更长时间的查询,我们将只得到部分结果。
I got a very simple version working. I don't quite have the predicate correct, as the equivalent mdfind call has additional results. Also, it requires two args, the first is the base pathname to work from with the second being the search term.
Here is the code:
The query call is asynchronous, so to be more complete, I should register a callback and have the run loop go continuously. As it is, I do a search for 5 seconds, so if we have a query that would take longer, we will get only partial results.