0

If you have a document open and want to unmount a volume, os x opens this alert panel, that the document is still in use by program x. How can you get notified about this in cocoa? I tried the DADiskArbitration framework, but this doesn't send a callback until the disk has successfully unmounted.

Have you any ideas?

Oath Comrade
  • 283
  • 2
  • 9

1 Answers1

0

You could invoke lsof using NSTask to get a list of open files. Use lsof +D /Volumes/<volume name> to narrow the search down to files open in the mounted volume you're interested in.

indragie
  • 18,002
  • 16
  • 95
  • 164
  • Thank you for your answer, I will try it out. I should mention that I have no experience with NSTask. Is there no library or framework to do that? – Oath Comrade Dec 24 '13 at 23:49
  • `NSTask` is really easy to use, there's no need for an additional library or framework. It's part of Foundation.framework. There's an example here: http://borkware.com/quickies/one?topic=nstask – indragie Dec 24 '13 at 23:51
  • OK, I get the task working and get string as output. This is not the only problem, but if I have for example a pdf open in preview, the task returns me three open files, all the same but in different "COMMANDS" (applications), namely finder preview and QuickLook. – Oath Comrade Dec 25 '13 at 00:20
  • Parse the output and put all the file paths in an `NSSet` so that duplicate paths are filtered out, and now you have a collection of unique file paths. – indragie Dec 25 '13 at 00:44
  • Thank you! I figured it out with your help. Though the parsing is a bit complicated to turn a string into objects. If someone needs the sourcecode, please email me. – Oath Comrade Dec 28 '13 at 14:24