[英]Notification when user empties trash?
How would my cocoa app receive a notification when the user empties their trash. 当用户清空垃圾桶时,我的可可应用如何收到通知。 This is what I have so far: 这是我到目前为止的内容:
NSNotificationCenter *notCenter = [[NSWorkspace sharedWorkspace]
notificationCenter];
AppDelegate *mainController = [[AppDelegate alloc] init];
[notCenter addObserver:mainController
selector:@selector(handleTrashEmpty)
name:NSWorkspaceRecycleOperation object:nil];
But when nothing shows up when the user empties their trash. 但是,当用户清空垃圾箱时却什么也没有出现。 Any ideas why this code is not working? 有什么想法为什么此代码不起作用?
1st way: 第一种方式:
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
2nd way: 第二种方式:
Keep on checking with a timer if the [folderList count]==0, means trash is emptied. 如果[folderList count] == 0,则继续使用计时器检查,这表示垃圾已清空。
NSError *error=nil;
NSString *path=[NSHomeDirectory() stringByAppendingPathComponent:@".Trash"];
NSArray *folderList=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
3rd way: 第三种方式:
watch ~/.Trash, "com.apple.carbon.core.DirectoryNotification" is posted when the trash is emptied. 观看〜/ .Trash,清空垃圾箱后会发布“ com.apple.carbon.core.DirectoryNotification”。
NSWorkspaceRecycleOperation is not a notification at all but a file operation constant passed to performFileOperation:source:destination:files:tag: NSWorkspaceRecycleOperation根本不是通知,而是传递给performFileOperation:source:destination:files:tag的文件操作常量:
you use the FSEvents api to monitor /.Trashes. 您使用FSEvents api监视/.Trash。 Here's some sample code: http://subversion.assembla.com/svn/quotamonitormenu/QuotaMonitorMenu/branches/QuotaMonitorMenuFaculty/StatusItemController.m 以下是一些示例代码: http : //subversion.assembla.com/svn/quotamonitormenu/QuotaMonitorMenu/branches/QuotaMonitorMenuFaculty/StatusItemController.m
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.