0

I'm starting a program that needs to keep track of external hard drives.
I'm looking for the best way to uniquely identify a hard drive across several computers (including windows computers with .Net down the road).

I looked at getting the UUID, but that appears to be different across computers. I was hoping to try to get the manufacturer serial number that's printed on the drive, but I don't know how to do it with Swift, if it's even possible.

Extra bonus if I could also tie this into detecting when a new HDD is mounted, but not a DVD.

tadman
  • 208,517
  • 23
  • 234
  • 262
AndyD273
  • 7,177
  • 12
  • 54
  • 92
  • Do you mean something like [this tool](http://apple.stackexchange.com/questions/135565/how-do-i-get-detailed-smart-disk-information-on-os-x-mavericks-or-later)? It's open source so you could probably dig around in there. – tadman Nov 09 '15 at 21:12
  • Interesting info here: http://stackoverflow.com/a/2021812/2227743 – Eric Aya Nov 09 '15 at 21:16
  • @tadman Hmm, yeah, that's interesting... Lots to dig through – AndyD273 Nov 10 '15 at 15:22

1 Answers1

2

Note that NSFileManager has this method

mountedVolumeURLsIncludingResourceValuesForKeys(_:options:)

and under options you can specify NSURLVolumeIdentifierKey. This is a temporary identifier (not consistent across restarts) but it is unique and you would be able to monitor newly added or ejected volumes this way.

I am sure there is also another key to tell you about the type of file system and other attributes that let you determine if it is a DVD.

Follow the link to Common File System Resource Keys from the documentation of above method.

Maybe something like

let attributes = try manager.attributesOfFileSystemForPath("/")

could also be of help. In particular, NSFileSystemNumber seems to be a unique number as well.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • hmm... It's kind of important that I find a consistent key, so that I can get the key on my computer, unmount it, take it to another computer, plug it in and get the same key. – AndyD273 Nov 09 '15 at 21:41