Re: Mount/Unmount events in Foundation tool
Re: Mount/Unmount events in Foundation tool
- Subject: Re: Mount/Unmount events in Foundation tool
- From: "R. Matthew Emerson" <email@hidden>
- Date: Thu, 25 Jan 2007 21:03:31 -0500
On Jan 25, 2007, at 6:31 PM, James Bucanek wrote:
I have a Foundation tool (daemon) that I would very much like to
get volume mount and unmount events. I can't get
NSWorkspaceDidMountNotification because I can't use NSWorkspace.
Is there some other event I can subscribe to, or is there a way of
subscribing to Carbon events for the same action from within a
Cocoa app? I already checked NSDistributedNotificationCenter, and
it doesn't fire any useful events on volume mount/unmount.
It would appear to be necessary to grovel through the DiskArbitration
framework headers.
It looks pretty straightforward, though. I was able to throw
together a trivial program in about 15 or 20 minutes from first
looking at DiskArbitration.h. Maybe it will help get you going.
#include <stdio.h>
#include <DiskArbitration/DiskArbitration.h>
void hello_disk(DADiskRef disk, void *context)
{
printf("disk %s appeared\n", DADiskGetBSDName(disk));
}
void goodbye_disk(DADiskRef disk, void *context)
{
printf("disk %s disappeared\n", DADiskGetBSDName(disk));
}
main()
{
DASessionRef session;
session = DASessionCreate(kCFAllocatorDefault);
DARegisterDiskAppearedCallback(session, NULL, hello_disk, NULL);
DARegisterDiskDisappearedCallback(session, NULL, goodbye_disk,
NULL);
DASessionScheduleWithRunLoop(session,
CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
CFRunLoopRun();
CFRelease(session);
exit(0);
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden