简体   繁体   English

当用户清空垃圾箱时,如何通知我的Cocoa应用程序?

[英]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 . 另一种选择是使用FNSubscribeFNSubscribeByPath 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.

相关问题 用户清空垃圾箱时收到通知? - Notification when user empties trash? 如何在WebView中通知我的Cocoa应用程序onClick事件? - How can my Cocoa application be notified of onClick events in a WebView? 当另一个可可应用程序终止时,一个Cocoa应用程序通知 - One Cocoa app notified when another cocoa app terminated 当应用程序移至垃圾箱或在Mac中被垃圾箱丢弃时如何获得通知? - How to get notified when an application moved to trash or an application trashed in mac? 当移动属于另一个应用程序的窗口时,如何通知我的应用程序? - How can my app be notified when a window belonging to another app is moved? 当用户将图像粘贴或拖动到NSImageView中时,如何通知我的代码? - How can my code get notified when the user pastes or drags an image into NSImageView? 如何在Cocoa应用程序中收到系统时间更改的通知? - How can I get notified of a system time change in my Cocoa application? 在OS X的Safari中更改/加载URL时如何通知可可应用程序? - How can a Cocoa application get notified when a URL is changed/loaded in Safari for OS X? 显示对象表时如何通知我? - How can my object be notified when its sheet is displayed? 在可可应用中将垃圾大小作为int检索 - Retrieve Trash size as an int in cocoa app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM