NSWorkspace
provides a notification, NSWorkspaceDidMountNotification
, when a disk is mounted. In outline you declare a notification handler, for example:
- (void) mountNotify:(NSNotification *)notification
{
// extract details from notification
NSDictionary *userInfo = notification.userInfo;
NSString *volumeMounted = userInfo[@"NSDevicePath"];
NSString *volumeDisplayName = userInfo[@"NSWorkspaceVolumeLocalizedNameKey"];
if (volumeMounted != nil)
{
// volume has been mounted
}
}
and register for notifications:
[[[NSWorkspace sharedWorkspace] notificationCenter]
addObserver:self
selector:@selector(mountNotify:)
name:NSWorkspaceDidMountNotification
object:nil
];
There is also a similar notification, NSWorkspaceDidUnmountNotification
, for when a disk is unmounted.
For more details see Apple's NSWorkspace
documentation.
HTH.