当用户清空垃圾箱时,如何通知我的 Cocoa 应用程序?
我的应用程序将一些文件放入垃圾箱,但也实现了撤消功能以将它们再次拉出。我需要知道用户是否清空垃圾箱,以便我可以清空我的撤消堆栈。
我是否需要监视文件系统事件才能实现此目的,或者是否有更简单的方法?
My app puts some files in the trash, but also implements undo to pull them back out again. I need to know if the user empties the trash so I can empty my undo stack.
Do I need to monitor file system events to achieve this, or is there an easier way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能最终不得不观看 ~/.Trash,但是当垃圾箱被清空时,会发布一条通知。它的名字是
“com.apple.carbon.core.DirectoryNotification”
(其他时候也发布过),但它的userInfo中似乎没有任何内容。但是,它确实有一个字符串作为对象,因此可能包含一些相关信息。我的快速测试似乎表明事实并非如此。 (它看起来像一个类似于"FNObject 555279-101"
的字符串)You'll probably have to end up watching ~/.Trash, but there is a notification posted when the trash is emptied. Its name is
"com.apple.carbon.core.DirectoryNotification"
(which is also posted at other times), but it doesn't seem to have anything in the userInfo. However, it does have a string as the object, so that might contain some relevant information. My quick tests seem to indicate that it doesn't. (It looks like a string that's something like"FNObject 555279-101"
)您可以使用 UKKQueue 来观看文件更改(空鞭打)通知:
http://www.cocoadev.com/index.pl?UKKQueue
You can use UKKQueue to watch file change (empty thrash) notifications:
http://www.cocoadev.com/index.pl?UKKQueue
另一种选择是使用
FNSubscribe
或FNSubscribeByPath
。该通知不会告诉您到底发生了什么,只是告诉您您订阅的目录发生了一些情况。Another option is to use
FNSubscribe
orFNSubscribeByPath
. The notification won't tell you exactly what happened, just that something happened to the directory you subscribed to.