[英]How can my Cocoa app be notified when the user empties the trash?
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? 我是否需要监视文件系统事件才能实现此目的,还是有更简单的方法?
You'll probably have to end up watching ~/.Trash, but there is a notification posted when the trash is emptied. 你可能会不得不结束了看〜/ .Trash, 但是当垃圾被清空张贴了通知。 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. 它的名字是"com.apple.carbon.core.DirectoryNotification"
(也在其他时间发布),但它似乎在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"
) (它看起来像一个类似"FNObject 555279-101"
的字符串)
You can use UKKQueue to watch file change (empty thrash) notifications: 您可以使用UKKQueue来观看文件更改(空捶打)通知:
http://www.cocoadev.com/index.pl?UKKQueue http://www.cocoadev.com/index.pl?UKKQueue
Another option is to use FNSubscribe
or FNSubscribeByPath
. 另一种选择是使用FNSubscribe
或FNSubscribeByPath
。 The notification won't tell you exactly what happened, just that something happened to the directory you subscribed to. 通知不会告诉您发生了什么,只是您订阅的目录发生了什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.