• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting disk mount notification with Foundation tools
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting disk mount notification with Foundation tools


  • Subject: Re: Getting disk mount notification with Foundation tools
  • From: Bill Bumgarner <email@hidden>
  • Date: Sat, 8 Jun 2002 15:53:30 -0400

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.

  • Follow-Ups:
    • Re: Getting disk mount notification with Foundation tools
      • From: Mike Vannorsdel <email@hidden>
  • Prev by Date: Toolbar and window resizing
  • Next by Date: Re: NSConnection, where'd my proxy go?
  • Previous by thread: Getting disk mount notification with Foundation tools
  • Next by thread: Re: Getting disk mount notification with Foundation tools
  • Index(es):
    • Date
    • Thread