is there a way to be notified by the system when an external volume/disk is loaded or ejected?
At present I rely on a timer, that keeping track of volumeCount, tells the app when volumeCount increases or decreases, but if possible I’d prefer a system-notification.
Suggestions will be appreciated.
FSEvents on OS X
Theres similar on Windows (dont recall the specific API)
Not sure about linux but I would expect there’s something
On macOS, this can be done with declares or plug-ins; you basically tap into the OS notification system. It’s what Backup to Go uses.
I’m not at my computer so, I’m not able to share any code or give you more pointers at the moment.
This makes me wonder, just how intense is the VolumeCount function and is there any reason not to check the VolumeCount every few seconds for new devices?
pretty sure that this is in macoslib and/or mbs
its not super expensive
but its more cpu intensive than it needs to be
@Tim Parnell [quote] This makes me wonder, just how intense is the VolumeCount function and is there any reason not to check the VolumeCount every few seconds for new devices?[/quote]
That is the reason why I’d like to switch to system-notification.
@Norman Palardy I already looked into macOSlib. I’ll look better into FSEvents. Thanks.
In MacOsLib I think its in FSEventModule (depending on which download you have)
If you use MBS Plugin wie have Events for that.
@Norman Palardy [quote]In MacOsLib I think its in FSEventModule[/quote]
Got it. I’ll see in the morning how to implement it. Thank you.
@Christian Schmitz At present I’ll try to do it without plugins. Thanks.
Just for the records: in macOSlib I found Cocoa.NSWorkspace. Among other notifications(sleep etc.) it notifies:
volume will unmount.
Thanks to those who contributed.