Re: Getting disk mount notification with Foundation tools
Re: Getting disk mount notification with Foundation tools
- Subject: Re: Getting disk mount notification with Foundation tools
- From: Andrew Salamon <email@hidden>
- Date: Thu, 12 May 2005 14:10:52 -0700
I realize this code is almost three years old, but it doesn't work
for me under 10.3.9. Does anyone have any idea why, or what I can do to
get mount notifications in a foundation tool? I'm currently looking
into the private DiskArbitration framework, but haven't found any
documentation on it. If anyone has sample code that would do what the
workspace code used to do, I'd appreciate pointers to it.
Thanks.
Andrew
On Jun 8, 2002, at 12:53 PM, Bill Bumgarner wrote:
You need to have a running NSRunLoop to receive workspace
notifications.
The following output....
2002-06-08 15:49:01.584 notiftest[5277] -mountNotification: --
NSConcreteNotification 80b40 {name = NSWorkspaceDidMountNotification;
object = <NSWorkspace: 0x7b2b0>; userInfo = <CFDictionary 0x807b0
[0x8016024c]>{count = 1, capacity = 1, pairs = (
2 : NSDevicePath = <CFString 0x6bdf0 [0x8016024c]>{contents =
"/Volumes/foo"}
)}}
2002-06-08 15:49:10.020 notiftest[5277] -unmountNotification: --
NSConcreteNotification 7d7a0 {name =
NSWorkspaceDidUnmountNotification; object = <NSWorkspace: 0x7b2b0>;
userInfo = <CFDictionary 0x81ab0 [0x8016024c]>{count = 1, capacity =
1, pairs = (
2 : NSDevicePath = <CFString 0x81bf0 [0x8016024c]>{contents =
"/Volumes/foo"}
)}}
... was generated by this code (the entire main.m for a Foundation
tool that also links against the Cocoa framework)..
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
@interface NotifTarget:NSObject
@end
@implementation NotifTarget
+ (void) mountNotification: (NSNotification *) aNotification
{
NSLog(@"-%@ -- %@", NSStringFromSelector(_cmd), aNotification);
}
+ (void) unmountNotification: (NSNotification *) aNotification
{
NSLog(@"-%@ -- %@", NSStringFromSelector(_cmd), aNotification);
}
@end
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver: [NotifTarget class]
selector: @selector(mountNotification:)
name: NSWorkspaceDidMountNotification
object: nil];
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver: [NotifTarget class]
selector: @selector(unmountNotification:)
name: NSWorkspaceDidUnmountNotification
object: nil];
[[NSRunLoop currentRunLoop] run];
[pool release];
return 0;
}
...note that the runloop in the above example will run forever. See
NSRunLoop for information on doing one-shot and run-til-date passes
through the run loop.
The NSWorkspace object is, more or less, a proxy to the mechanisms
that provide the cross-application Workspace functionality. As such,
every runtime that invokes the +sharedWorkspace method will have a
different instance returned even though the instances effectively
point to the same backing mechanism.
b.bum
On Saturday, June 8, 2002, at 01:55 PM,
email@hidden wrote:
Date: Sat, 08 Jun 2002 00:53:42 -0600
Subject: Getting disk mount notification with Foundation tools
From: Mike Vannorsdel <email@hidden>
To: Cocoa Dev <email@hidden>
I have a Foundation tool and I need to get disk mounting
notifications.
Since it's a Foundation tool, I can't use AppKit's NSWorkspace
methods.
I've tried linking to AppKit and registering for the notification, but
didn't receive the notification (or any workspace notifications for
that
matter). I did get a valid NSWorkspace object which did have a valid
notification center. But the instance of NSWorkspace was not the
same as
the "real" AppKit applications were getting, which probably explains
the
lack of any notifications.
So how do I get notifications of mounted disks from Foundation? This
tool
is also a daemon (forks), if that matters.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden