I know there is a MBS plugin that will notify a xojo application whenever a volume gets mounted. But it is a Carbon plugin (if I remember well), which is depreciated. Is there another way, besides checking the VolumeCount within a Timer control?
The carbon event system is the base of the Cooca one. It won’t go away in my opinion.
Works like a charm.
I tried to get a folderitem from the NSDevicePath value in the UserInfo dictionary. But whatever pathmode I try, the folderitem I try to get is Nil.
What did work was iterating through the volumes using
f = FolderItem.DriveAt(i)
And compared the NativePath property with the NSDevicePath.
I wonder wonder if there is a better way of getting a FolderItem reference to the mounted volume
Should I remove the Observer when I’m not using it anymore?
What happens internally when I remove an observer when this observer is no longer there?
I figured this one out by checking the values in the the UserInfo property dictionary. One of the values is in fact a FolderItem. So, no need to do the crazy things I did.
I simply used the “NSWorkspaceVolumeURLKey” entry to get the FolderItem value for a volume I was listening for.
MBS Plugin does unregistration in destructor if needed.
I use MacUSBNotificationMBS and USBNotificationMBS to check if a user has attached/removed a device (eg memory stick, drive, server, etc) and refresh the list of possible storage options. It works really well for me.
I would not have expected a USB notification to be called when one connects to a network share…
Not doubting it actually works but… should it (based on the function name)?
Now you have me doubting myself, as I also check for new or removed volumes when the Activate Event is activated, so maybe I show the new server volume there. Hmmm…