Is there an easy way to get the serial number of all the hard disks in a Mac using an API?
Basically, I'm looking for a unique identifier for the hard disk with which I can figure out whether the hard disk has been used (or referred to) by my application or not.
Please let me know if there is any other solution.
Note: I need this solution for 10.4 and above.
Next to each hard drive, you'll see the drive's serial number. This is the number that the manufacturer has assigned to the drive. That's a quick and easy way to read your hard drive's serial number!
The following will list the serial numbers on the SATA-bus. You don't get to know which device it is as is but you can do it with some scripting/parsing. I've used "sed" to remove all the spaces and "awk" to isolate just the serial in case you are not familiar:
$ system_profiler SPSerialATADataType -detailLevel medium | grep Serial | sed -e 's/[\<\>\"\ ]//g' | -F':' '{print $2}'
From the command line:
ioreg -rd1 -w0 -c AppleAHCIDiskDriver | grep Serial
This gives you the serial number of the built-in hard disk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With